mirror of
https://github.com/fluencelabs/redis
synced 2025-06-22 05:21:33 +00:00
zmalloc.c: remove thread safe mode, it's the default way.
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user