mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-23 00:28:26 -05:00
zmalloc.c: remove thread safe mode, it's the default way.
This commit is contained in:
parent
9390c384b8
commit
6eb51bf1ec
@ -3673,7 +3673,6 @@ int main(int argc, char **argv) {
|
|||||||
spt_init(argc, argv);
|
spt_init(argc, argv);
|
||||||
#endif
|
#endif
|
||||||
setlocale(LC_COLLATE,"");
|
setlocale(LC_COLLATE,"");
|
||||||
zmalloc_enable_thread_safeness();
|
|
||||||
zmalloc_set_oom_handler(redisOutOfMemoryHandler);
|
zmalloc_set_oom_handler(redisOutOfMemoryHandler);
|
||||||
srand(time(NULL)^getpid());
|
srand(time(NULL)^getpid());
|
||||||
gettimeofday(&tv,NULL);
|
gettimeofday(&tv,NULL);
|
||||||
|
@ -73,25 +73,16 @@ void zlibc_free(void *ptr) {
|
|||||||
#define update_zmalloc_stat_alloc(__n) do { \
|
#define update_zmalloc_stat_alloc(__n) do { \
|
||||||
size_t _n = (__n); \
|
size_t _n = (__n); \
|
||||||
if (_n&(sizeof(long)-1)) _n += sizeof(long)-(_n&(sizeof(long)-1)); \
|
if (_n&(sizeof(long)-1)) _n += sizeof(long)-(_n&(sizeof(long)-1)); \
|
||||||
if (zmalloc_thread_safe) { \
|
|
||||||
atomicIncr(used_memory,__n); \
|
atomicIncr(used_memory,__n); \
|
||||||
} else { \
|
|
||||||
used_memory += _n; \
|
|
||||||
} \
|
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#define update_zmalloc_stat_free(__n) do { \
|
#define update_zmalloc_stat_free(__n) do { \
|
||||||
size_t _n = (__n); \
|
size_t _n = (__n); \
|
||||||
if (_n&(sizeof(long)-1)) _n += sizeof(long)-(_n&(sizeof(long)-1)); \
|
if (_n&(sizeof(long)-1)) _n += sizeof(long)-(_n&(sizeof(long)-1)); \
|
||||||
if (zmalloc_thread_safe) { \
|
|
||||||
atomicDecr(used_memory,__n); \
|
atomicDecr(used_memory,__n); \
|
||||||
} else { \
|
|
||||||
used_memory -= _n; \
|
|
||||||
} \
|
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
static size_t used_memory = 0;
|
static size_t used_memory = 0;
|
||||||
static int zmalloc_thread_safe = 0;
|
|
||||||
pthread_mutex_t used_memory_mutex = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t used_memory_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
static void zmalloc_default_oom(size_t size) {
|
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 zmalloc_used_memory(void) {
|
||||||
size_t um;
|
size_t um;
|
||||||
|
|
||||||
if (zmalloc_thread_safe) {
|
|
||||||
atomicGet(used_memory,um);
|
atomicGet(used_memory,um);
|
||||||
} else {
|
|
||||||
um = used_memory;
|
|
||||||
}
|
|
||||||
return um;
|
return um;
|
||||||
}
|
}
|
||||||
|
|
||||||
void zmalloc_enable_thread_safeness(void) {
|
|
||||||
zmalloc_thread_safe = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void zmalloc_set_oom_handler(void (*oom_handler)(size_t)) {
|
void zmalloc_set_oom_handler(void (*oom_handler)(size_t)) {
|
||||||
zmalloc_oom_handler = oom_handler;
|
zmalloc_oom_handler = oom_handler;
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,6 @@ void *zrealloc(void *ptr, size_t size);
|
|||||||
void zfree(void *ptr);
|
void zfree(void *ptr);
|
||||||
char *zstrdup(const char *s);
|
char *zstrdup(const char *s);
|
||||||
size_t zmalloc_used_memory(void);
|
size_t zmalloc_used_memory(void);
|
||||||
void zmalloc_enable_thread_safeness(void);
|
|
||||||
void zmalloc_set_oom_handler(void (*oom_handler)(size_t));
|
void zmalloc_set_oom_handler(void (*oom_handler)(size_t));
|
||||||
float zmalloc_get_fragmentation_ratio(size_t rss);
|
float zmalloc_get_fragmentation_ratio(size_t rss);
|
||||||
size_t zmalloc_get_rss(void);
|
size_t zmalloc_get_rss(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user