about summary refs log tree commit diff
path: root/nscd/cache.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2006-05-29 07:00:16 +0000
committerUlrich Drepper <drepper@redhat.com>2006-05-29 07:00:16 +0000
commit9636a217e4a0a73113ffdaa9a2f0c8d1749cf1d9 (patch)
treeeb310947247d941a4c71ca880fd1a9a132c8c4a0 /nscd/cache.c
parentab50b2ec0193ad37c73d34c0e98ff16486af237e (diff)
downloadglibc-9636a217e4a0a73113ffdaa9a2f0c8d1749cf1d9.tar.gz
glibc-9636a217e4a0a73113ffdaa9a2f0c8d1749cf1d9.tar.xz
glibc-9636a217e4a0a73113ffdaa9a2f0c8d1749cf1d9.zip
* nscd/nscd.h (struct database_dyn): Add prunelock field.
	* nscd/cache.c (prune_cache): Take prunelock before starting the
	work.  Just return in case it is already taken.

	(inet6_option_alloc): Now a simple wrapper around option_alloc.
Diffstat (limited to 'nscd/cache.c')
-rw-r--r--nscd/cache.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/nscd/cache.c b/nscd/cache.c
index 787f8b46f5..899e2caf77 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.
 
@@ -198,6 +198,13 @@ prune_cache (struct database_dyn *table, time_t now)
   if (cnt == 0)
     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 ;
+
   /* If we check for the modification of the underlying file we invalidate
      the entries also in this case.  */
   if (table->check_file)
@@ -455,4 +462,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);
 }