mirror of
https://sourceware.org/git/glibc.git
synced 2025-01-03 08:11:08 +00:00
(prune_cache): Move test for modified file outside of locking.
This commit is contained in:
parent
9251c5687f
commit
02aa27fe12
38
nscd/cache.c
38
nscd/cache.c
@ -229,22 +229,9 @@ prune_cache (struct database_dyn *table, time_t now, int fd)
|
|||||||
return;
|
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
|
/* If we check for the modification of the underlying file we invalidate
|
||||||
the entries also in this case. */
|
the entries also in this case. */
|
||||||
if (table->check_file)
|
if (table->check_file && now != LONG_MAX)
|
||||||
{
|
{
|
||||||
struct stat64 st;
|
struct stat64 st;
|
||||||
|
|
||||||
@ -269,6 +256,21 @@ 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.
|
/* 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,
|
Note that for the initial step, finding the entries to be removed,
|
||||||
@ -285,6 +287,7 @@ prune_cache (struct database_dyn *table, time_t now, int fd)
|
|||||||
dbg_log (_("pruning %s cache; time %ld"),
|
dbg_log (_("pruning %s cache; time %ld"),
|
||||||
dbnames[table - dbs], (long int) now);
|
dbnames[table - dbs], (long int) now);
|
||||||
|
|
||||||
|
time_t next_timeout = LONG_MAX;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
ref_t run = table->head->array[--cnt];
|
ref_t run = table->head->array[--cnt];
|
||||||
@ -363,14 +366,17 @@ prune_cache (struct database_dyn *table, time_t now, int fd)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
assert (dh->usable);
|
{
|
||||||
|
assert (dh->usable);
|
||||||
|
next_timeout = MIN (next_timeout, dh->timeout);
|
||||||
|
}
|
||||||
|
|
||||||
run = runp->next;
|
run = runp->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (cnt > 0);
|
while (cnt > 0);
|
||||||
|
|
||||||
if (fd != -1)
|
if (__builtin_expect (fd != -1, 0))
|
||||||
{
|
{
|
||||||
/* Reply to the INVALIDATE initiator that the cache has been
|
/* Reply to the INVALIDATE initiator that the cache has been
|
||||||
invalidated. */
|
invalidated. */
|
||||||
|
Loading…
Reference in New Issue
Block a user