summaryrefslogtreecommitdiff
path: root/nscd/cache.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2006-05-30 17:32:08 +0000
committerUlrich Drepper <drepper@redhat.com>2006-05-30 17:32:08 +0000
commit902c429174f9660eaeb255695f8f335afbfdc54a (patch)
tree2cd188cbcdfd3b82be6aa3187b7755c12b607654 /nscd/cache.c
parentecc685684824cdbb971438ed944794d4bff4547d (diff)
* nscd/nscd.h (prune_cache): Add fd argument to prototype.cvs/fedora-glibc-20060531T1322
* nscd/nscd.c (parse_opt): Read response from INVALIDATE request to make sure the database has been already invalidated. * nscd/cache.c (prune_cache): Add fd argument. Write response to fd after the cache has been invalidated. Use pthread_mutex_lock rather than pthread_mutex_trylock if fd != -1. * nscd/connections.c (invalidate_cache): Add fd argument, write response to fd if not calling prune_cache, pass fd to prune_cache. (handle_request): Adjust invalidate_cache caller. (nscd_run): Pass -1 as fd to prune_cache.
Diffstat (limited to 'nscd/cache.c')
-rw-r--r--nscd/cache.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/nscd/cache.c b/nscd/cache.c
index 899e2caf77..be9be2aa4f 100644
--- a/nscd/cache.c
+++ b/nscd/cache.c
@@ -190,20 +190,34 @@ cache_add (int type, const void *key, size_t len, struct datahead *packet,
free the data structures since some hash table entries share the same
data. */
void
-prune_cache (struct database_dyn *table, time_t now)
+prune_cache (struct database_dyn *table, time_t now, int fd)
{
size_t cnt = table->head->module;
/* If this table is not actually used don't do anything. */
if (cnt == 0)
- return;
+ {
+ if (fd != -1)
+ {
+ /* Reply to the INVALIDATE initiator. */
+ int32_t resp = 0;
+ writeall (fd, &resp, sizeof (resp));
+ }
+ return;
+ }
/* This function can be called from the cleanup thread but also in
response to an invalidate command. Make sure only one thread is
- running. No need for the second to wait around. */
- if (pthread_mutex_trylock (&table->prunelock) != 0)
- /* Te work is already being done. */
- return ;
+ running. When not serving INVALIDATE request, no need for the
+ second to wait around. */
+ if (fd == -1)
+ {
+ if (pthread_mutex_trylock (&table->prunelock) != 0)
+ /* The work is already being done. */
+ return;
+ }
+ else
+ pthread_mutex_lock (&table->prunelock);
/* If we check for the modification of the underlying file we invalidate
the entries also in this case. */
@@ -374,6 +388,14 @@ prune_cache (struct database_dyn *table, time_t now)
}
while (cnt > 0);
+ if (fd != -1)
+ {
+ /* Reply to the INVALIDATE initiator that the cache has been
+ invalidated. */
+ int32_t resp = 0;
+ writeall (fd, &resp, sizeof (resp));
+ }
+
if (first <= last)
{
struct hashentry *head = NULL;