From 902c429174f9660eaeb255695f8f335afbfdc54a Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 30 May 2006 17:32:08 +0000 Subject: * nscd/nscd.h (prune_cache): Add fd argument to prototype. * 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. --- nscd/cache.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'nscd/cache.c') 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; -- cgit 1.4.1