diff --git a/src/server.c b/src/server.c index 4fd2f9438..0ef3168fe 100644 --- a/src/server.c +++ b/src/server.c @@ -3673,7 +3673,6 @@ int main(int argc, char **argv) { spt_init(argc, argv); #endif setlocale(LC_COLLATE,""); - zmalloc_enable_thread_safeness(); zmalloc_set_oom_handler(redisOutOfMemoryHandler); srand(time(NULL)^getpid()); gettimeofday(&tv,NULL); diff --git a/src/zmalloc.c b/src/zmalloc.c index dfcfc01d4..094dd80fa 100644 --- a/src/zmalloc.c +++ b/src/zmalloc.c @@ -73,25 +73,16 @@ void zlibc_free(void *ptr) { #define update_zmalloc_stat_alloc(__n) do { \ size_t _n = (__n); \ if (_n&(sizeof(long)-1)) _n += sizeof(long)-(_n&(sizeof(long)-1)); \ - if (zmalloc_thread_safe) { \ - atomicIncr(used_memory,__n); \ - } else { \ - used_memory += _n; \ - } \ + atomicIncr(used_memory,__n); \ } while(0) #define update_zmalloc_stat_free(__n) do { \ size_t _n = (__n); \ if (_n&(sizeof(long)-1)) _n += sizeof(long)-(_n&(sizeof(long)-1)); \ - if (zmalloc_thread_safe) { \ - atomicDecr(used_memory,__n); \ - } else { \ - used_memory -= _n; \ - } \ + atomicDecr(used_memory,__n); \ } while(0) static size_t used_memory = 0; -static int zmalloc_thread_safe = 0; pthread_mutex_t used_memory_mutex = PTHREAD_MUTEX_INITIALIZER; static void zmalloc_default_oom(size_t size) { @@ -220,19 +211,10 @@ char *zstrdup(const char *s) { size_t zmalloc_used_memory(void) { size_t um; - - if (zmalloc_thread_safe) { - atomicGet(used_memory,um); - } else { - um = used_memory; - } + atomicGet(used_memory,um); return um; } -void zmalloc_enable_thread_safeness(void) { - zmalloc_thread_safe = 1; -} - void zmalloc_set_oom_handler(void (*oom_handler)(size_t)) { zmalloc_oom_handler = oom_handler; } diff --git a/src/zmalloc.h b/src/zmalloc.h index b6d4e1d97..64f2f36aa 100644 --- a/src/zmalloc.h +++ b/src/zmalloc.h @@ -78,7 +78,6 @@ void *zrealloc(void *ptr, size_t size); void zfree(void *ptr); char *zstrdup(const char *s); size_t zmalloc_used_memory(void); -void zmalloc_enable_thread_safeness(void); void zmalloc_set_oom_handler(void (*oom_handler)(size_t)); float zmalloc_get_fragmentation_ratio(size_t rss); size_t zmalloc_get_rss(void);