Lines Matching refs:cache

41 void cache_set_limit(cache_t *cache, int limit) {  in cache_set_limit()  argument
42 pthread_mutex_lock(&cache->mutex); in cache_set_limit()
43 cache->limit = limit; in cache_set_limit()
44 pthread_mutex_unlock(&cache->mutex); in cache_set_limit()
56 void cache_destroy(cache_t *cache) { in cache_destroy() argument
57 while (!STAILQ_EMPTY(&cache->head)) { in cache_destroy()
58 struct cache_free_s *o = STAILQ_FIRST(&cache->head); in cache_destroy()
59 STAILQ_REMOVE_HEAD(&cache->head, c_next); in cache_destroy()
62 free(cache->name); in cache_destroy()
63 pthread_mutex_destroy(&cache->mutex); in cache_destroy()
64 free(cache); in cache_destroy()
67 void* cache_alloc(cache_t *cache) { in cache_alloc() argument
69 pthread_mutex_lock(&cache->mutex); in cache_alloc()
70 ret = do_cache_alloc(cache); in cache_alloc()
71 pthread_mutex_unlock(&cache->mutex); in cache_alloc()
75 void* do_cache_alloc(cache_t *cache) { in do_cache_alloc() argument
78 if (cache->freecurr > 0) { in do_cache_alloc()
79 ret = STAILQ_FIRST(&cache->head); in do_cache_alloc()
80 STAILQ_REMOVE_HEAD(&cache->head, c_next); in do_cache_alloc()
82 cache->freecurr--; in do_cache_alloc()
83 } else if (cache->limit == 0 || cache->total < cache->limit) { in do_cache_alloc()
84 object = ret = malloc(cache->bufsize); in do_cache_alloc()
88 cache->total++; in do_cache_alloc()
100 memcpy(((char*)ret) + cache->bufsize - (2 * sizeof(redzone_pattern)), in do_cache_alloc()
108 void cache_free(cache_t *cache, void *ptr) { in cache_free() argument
109 pthread_mutex_lock(&cache->mutex); in cache_free()
110 do_cache_free(cache, ptr); in cache_free()
111 pthread_mutex_unlock(&cache->mutex); in cache_free()
114 void do_cache_free(cache_t *cache, void *ptr) { in do_cache_free() argument
117 if (memcmp(((char*)ptr) + cache->bufsize - (2 * sizeof(redzone_pattern)), in do_cache_free()
132 if (cache->limit != 0 && cache->limit < cache->total) { in do_cache_free()
134 cache->total--; in do_cache_free()
136 STAILQ_INSERT_HEAD(&cache->head, (struct cache_free_s *)ptr, c_next); in do_cache_free()
137 cache->freecurr++; in do_cache_free()