diff options
author | Ulrich Drepper <drepper@redhat.com> | 2007-11-06 00:45:40 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2007-11-06 00:45:40 +0000 |
commit | ffb1b882828a6fa71fb4e9be1c30cacafb3c70c3 (patch) | |
tree | 9819639dc6d59b7cfbd3630b7027b57c0d696f47 /nscd/cache.c | |
parent | 41ff2a4999f64527a0552c6a9c203157e161fa97 (diff) | |
download | glibc-ffb1b882828a6fa71fb4e9be1c30cacafb3c70c3.tar.gz glibc-ffb1b882828a6fa71fb4e9be1c30cacafb3c70c3.tar.xz glibc-ffb1b882828a6fa71fb4e9be1c30cacafb3c70c3.zip |
* nscd/aicache.c (addhstaiX): Check herrno after IPv4 lookup only
when the lookup call failed. * nscd/nscd.h (struct database_dyn): Rename prunelock to prune_lock. Add prune_cond and wakeup_time. (CACHE_PRUNE_INTERNAL): Define. Update declarations of prune_cache and setup_thread. * nscd/connections.c (dbs): Update initializers. (CACHE_PRUNE_INTERNAL): Moved to nscd.h. (nscd_init): Default number of threads is now 4. (invalidate_cache): Take lock before calling prune_cache. (handle_request): If SELinux forbids the request, say so. (readylist_cond): Use static initializer. (nscd_run_prune): New function. Used only by pruning threads. (nscd_run_worder): Renamed from nscd_run. Remove support for pruning here. (fd_ready): Update nscd_run reference. (start_threads): No need to initialize readylist_cond. Start pruning threads separately. * nscd/nscd_setup_thread.c: Change return value type to int and always return 0. * sysdeps/unix/sysv/linux/nscd_setup_thread.c: Change return value type to int and return nonzero value if we can use the TID address hack. * nscd/cache.c (cache_add): If next wakeup time of cleanup thread for the database is later than the new entry's timeout, update the wakeup time and wake the cleanup thread. (prune_cache): Return seconds the next entry in the database is still valid. Remove locking for pruning here. * nscd/nscd.conf: Document default number of threads.
Diffstat (limited to 'nscd/cache.c')
-rw-r--r-- | nscd/cache.c | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/nscd/cache.c b/nscd/cache.c index e5a8499e5b..ea79c38548 100644 --- a/nscd/cache.c +++ b/nscd/cache.c @@ -197,6 +197,20 @@ cache_add (int type, const void *key, size_t len, struct datahead *packet, (char *) &table->head->array[hash] - (char *) table->head + sizeof (ref_t), MS_ASYNC); + /* Perhaps the prune thread for the data is not running in a long + time. Wake it if necessary. */ + time_t next_wakeup = table->wakeup_time; + while (next_wakeup + CACHE_PRUNE_INTERVAL > packet->timeout) + if (atomic_compare_and_exchange_bool_acq (&table->wakeup_time, + packet->timeout, + next_wakeup) == 0) + { + pthread_cond_signal (&table->prune_cond); + break; + } + else + next_wakeup = table->wakeup_time; + return 0; } @@ -212,7 +226,7 @@ cache_add (int type, const void *key, size_t len, struct datahead *packet, actually remove them. This is complicated by the way we have to free the data structures since some hash table entries share the same data. */ -void +time_t prune_cache (struct database_dyn *table, time_t now, int fd) { size_t cnt = table->head->module; @@ -226,7 +240,9 @@ prune_cache (struct database_dyn *table, time_t now, int fd) int32_t resp = 0; writeall (fd, &resp, sizeof (resp)); } - return; + + /* No need to do this again anytime soon. */ + return 24 * 60 * 60; } /* If we check for the modification of the underlying file we invalidate @@ -256,21 +272,6 @@ prune_cache (struct database_dyn *table, time_t now, int fd) } } - /* This function can be called from the cleanup thread but also in - response to an invalidate command. Make sure only one thread is - running. When not serving INVALIDATE request, no need for the - second thread to wait around. */ - if (__builtin_expect (pthread_mutex_trylock (&table->prunelock) != 0, 0)) - { - /* The work is already being done. */ - if (fd == -1) - return; - - /* We have to wait until the thread is done and then run again - so that the large NOW value invalidates all entries. */ - pthread_mutex_lock (&table->prunelock); - } - /* We run through the table and find values which are not valid anymore. Note that for the initial step, finding the entries to be removed, @@ -473,5 +474,5 @@ prune_cache (struct database_dyn *table, time_t now, int fd) if (any) gc (table); - pthread_mutex_unlock (&table->prunelock); + return next_timeout - now; } |