Skip to content

Commit 6eb51bf

Browse files
committed
zmalloc.c: remove thread safe mode, it's the default way.
1 parent 9390c38 commit 6eb51bf

File tree

3 files changed

+3
-23
lines changed

3 files changed

+3
-23
lines changed

src/server.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3673,7 +3673,6 @@ int main(int argc, char **argv) {
36733673
spt_init(argc, argv);
36743674
#endif
36753675
setlocale(LC_COLLATE,"");
3676-
zmalloc_enable_thread_safeness();
36773676
zmalloc_set_oom_handler(redisOutOfMemoryHandler);
36783677
srand(time(NULL)^getpid());
36793678
gettimeofday(&tv,NULL);

src/zmalloc.c

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,16 @@ void zlibc_free(void *ptr) {
7373
#define update_zmalloc_stat_alloc(__n) do { \
7474
size_t _n = (__n); \
7575
if (_n&(sizeof(long)-1)) _n += sizeof(long)-(_n&(sizeof(long)-1)); \
76-
if (zmalloc_thread_safe) { \
77-
atomicIncr(used_memory,__n); \
78-
} else { \
79-
used_memory += _n; \
80-
} \
76+
atomicIncr(used_memory,__n); \
8177
} while(0)
8278

8379
#define update_zmalloc_stat_free(__n) do { \
8480
size_t _n = (__n); \
8581
if (_n&(sizeof(long)-1)) _n += sizeof(long)-(_n&(sizeof(long)-1)); \
86-
if (zmalloc_thread_safe) { \
87-
atomicDecr(used_memory,__n); \
88-
} else { \
89-
used_memory -= _n; \
90-
} \
82+
atomicDecr(used_memory,__n); \
9183
} while(0)
9284

9385
static size_t used_memory = 0;
94-
static int zmalloc_thread_safe = 0;
9586
pthread_mutex_t used_memory_mutex = PTHREAD_MUTEX_INITIALIZER;
9687

9788
static void zmalloc_default_oom(size_t size) {
@@ -220,19 +211,10 @@ char *zstrdup(const char *s) {
220211

221212
size_t zmalloc_used_memory(void) {
222213
size_t um;
223-
224-
if (zmalloc_thread_safe) {
225-
atomicGet(used_memory,um);
226-
} else {
227-
um = used_memory;
228-
}
214+
atomicGet(used_memory,um);
229215
return um;
230216
}
231217

232-
void zmalloc_enable_thread_safeness(void) {
233-
zmalloc_thread_safe = 1;
234-
}
235-
236218
void zmalloc_set_oom_handler(void (*oom_handler)(size_t)) {
237219
zmalloc_oom_handler = oom_handler;
238220
}

src/zmalloc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ void *zrealloc(void *ptr, size_t size);
7878
void zfree(void *ptr);
7979
char *zstrdup(const char *s);
8080
size_t zmalloc_used_memory(void);
81-
void zmalloc_enable_thread_safeness(void);
8281
void zmalloc_set_oom_handler(void (*oom_handler)(size_t));
8382
float zmalloc_get_fragmentation_ratio(size_t rss);
8483
size_t zmalloc_get_rss(void);

0 commit comments

Comments
 (0)