X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Flibmemcachedprotocol%2Fcache.c;h=1de8b0a6cf5614280204be5e7f3801c9836ed351;hb=01c5e0ed8d3d9c72ea192792d1c49a50e756d635;hp=1699f73513348647c551b2bf1ca1feba48abd641;hpb=808f81dba2553a1e552e8f3cea3ee376ad7d3558;p=awesomized%2Flibmemcached diff --git a/src/libmemcachedprotocol/cache.c b/src/libmemcachedprotocol/cache.c index 1699f735..1de8b0a6 100644 --- a/src/libmemcachedprotocol/cache.c +++ b/src/libmemcachedprotocol/cache.c @@ -19,16 +19,17 @@ #include #include -#ifndef NDEBUG -# include -#endif - #include "libmemcachedprotocol/common.h" -#ifndef NDEBUG +#ifndef HAVE_UMEM_H + +# ifndef NDEBUG +# include + const uint64_t redzone_pattern = 0xdeadbeefcafebabe; int cache_error = 0; -#endif + +# endif const size_t initial_pool_size = 64; @@ -52,11 +53,11 @@ cache_t *cache_create(const char *name, size_t bufsize, size_t align, ret->constructor = constructor; ret->destructor = destructor; -#ifndef NDEBUG +# ifndef NDEBUG ret->bufsize = bufsize + 2 * sizeof(redzone_pattern); -#else +# else ret->bufsize = bufsize; -#endif +# endif (void) align; @@ -64,12 +65,12 @@ cache_t *cache_create(const char *name, size_t bufsize, size_t align, } static inline void *get_object(void *ptr) { -#ifndef NDEBUG +# ifndef NDEBUG uint64_t *pre = ptr; return pre + 1; -#else +# else return ptr; -#endif +# endif } void cache_destroy(cache_t *cache) { @@ -105,7 +106,7 @@ void *cache_alloc(cache_t *cache) { } pthread_mutex_unlock(&cache->mutex); -#ifndef NDEBUG +# ifndef NDEBUG if (object) { /* add a simple form of buffer-check */ uint64_t *pre = ret; @@ -114,7 +115,7 @@ void *cache_alloc(cache_t *cache) { memcpy(((char *) ret) + cache->bufsize - (2 * sizeof(redzone_pattern)), &redzone_pattern, sizeof(redzone_pattern)); } -#endif +# endif return object; } @@ -122,7 +123,7 @@ void *cache_alloc(cache_t *cache) { void cache_free(cache_t *cache, void *ptr) { pthread_mutex_lock(&cache->mutex); -#ifndef NDEBUG +# ifndef NDEBUG /* validate redzone... */ if (memcmp(((char *) ptr) + cache->bufsize - (2 * sizeof(redzone_pattern)), &redzone_pattern, sizeof(redzone_pattern)) @@ -142,7 +143,7 @@ void cache_free(cache_t *cache, void *ptr) { return; } ptr = pre; -#endif +# endif if (cache->freecurr < cache->freetotal) { cache->ptr[cache->freecurr++] = ptr; } else { @@ -162,3 +163,5 @@ void cache_free(cache_t *cache, void *ptr) { } pthread_mutex_unlock(&cache->mutex); } + +#endif // HAVE_UMEM_H