summaryrefslogtreecommitdiff
path: root/nscd/cache.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2006-05-31 15:10:35 +0000
committerJakub Jelinek <jakub@redhat.com>2006-05-31 15:10:35 +0000
commit2774ea772499f5779e846646824784a44377c69a (patch)
tree8c23b862c87c0056b7ef8296f527ca580d5e15a5 /nscd/cache.c
parente482d83fb7eedcb449bfe80a6aa240cbd114c571 (diff)
Updated to fedora-glibc-20060531T1322cvs/fedora-glibc-2_4_90-11
Diffstat (limited to 'nscd/cache.c')
-rw-r--r--nscd/cache.c37
1 files changed, 34 insertions, 3 deletions
diff --git a/nscd/cache.c b/nscd/cache.c
index 787f8b46f5..be9be2aa4f 100644
--- a/nscd/cache.c
+++ b/nscd/cache.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1998, 1999, 2003, 2004, 2005 Free Software Foundation, Inc.
+/* Copyright (c) 1998, 1999, 2003-2005, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
@@ -190,13 +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. 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. */
@@ -367,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;
@@ -455,4 +484,6 @@ prune_cache (struct database_dyn *table, time_t now)
/* Run garbage collection if any entry has been removed or replaced. */
if (any)
gc (table);
+
+ pthread_mutex_unlock (&table->prunelock);
}