diff options
author | Ulrich Drepper <drepper@redhat.com> | 2007-11-25 21:08:01 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2007-11-25 21:08:01 +0000 |
commit | 30294ea4495e48e0103fee4d855737a281cc49fa (patch) | |
tree | 23a6e4b71c9fb7758596f212085e0ce8eaf7e4b9 /nscd/cache.c | |
parent | 609bb0712d522828bf52eb539d0b590ae153e55f (diff) | |
download | glibc-30294ea4495e48e0103fee4d855737a281cc49fa.zip glibc-30294ea4495e48e0103fee4d855737a281cc49fa.tar.gz glibc-30294ea4495e48e0103fee4d855737a281cc49fa.tar.bz2 |
* nscd/nscd.h (MAX_STACK_USE): Define.
* nscd/mem.c (MAX_STACK_USE): Remove definition here.
(gc): Initialize stack_used based on allocation in prune_cache.
* nscd/cache.c (prune_cache): Use heap for mark array if necessary.
Clear array bfore use.
* nscd/aicache.c (addhstaiX): Update statistics counter in case
memory allocate failed.
Diffstat (limited to 'nscd/cache.c')
-rw-r--r-- | nscd/cache.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/nscd/cache.c b/nscd/cache.c index 4d812e2..4065dac 100644 --- a/nscd/cache.c +++ b/nscd/cache.c @@ -36,6 +36,10 @@ #include "dbg_log.h" +/* Wrapper functions with error checking for standard functions. */ +extern void *xcalloc (size_t n, size_t s); + + /* Number of times a value is reloaded without being used. UINT_MAX means unlimited. */ unsigned int reload_count = DEFAULT_RELOAD_LIMIT; @@ -278,7 +282,20 @@ prune_cache (struct database_dyn *table, time_t now, int fd) we don't need to get any lock. It is at all timed assured that the linked lists are set up correctly and that no second thread prunes the cache. */ - bool mark[cnt]; + bool *mark; + size_t memory_needed = cnt * sizeof (bool); + bool mark_use_alloca; + if (__builtin_expect (memory_needed <= MAX_STACK_USE, 1)) + { + mark = alloca (cnt * sizeof (bool)); + memset (mark, '\0', memory_needed); + mark_use_alloca = true; + } + else + { + mark = xcalloc (1, memory_needed); + mark_use_alloca = false; + } size_t first = cnt + 1; size_t last = 0; char *const data = table->data; @@ -471,6 +488,9 @@ prune_cache (struct database_dyn *table, time_t now, int fd) } } + if (__builtin_expect (mark_use_alloca, 0)) + free (mark); + /* Run garbage collection if any entry has been removed or replaced. */ if (any) gc (table); |