提交 d3277ecd 编写于 作者: A antirez

More precise memory used guesswork in zmalloc.c

上级 66c8853f
...@@ -40,7 +40,9 @@ ...@@ -40,7 +40,9 @@
#define PREFIX_SIZE sizeof(size_t) #define PREFIX_SIZE sizeof(size_t)
#endif #endif
#define increment_used_memory(_n) do { \ #define increment_used_memory(__n) do { \
size_t _n = (__n); \
if (_n&(sizeof(long)-1)) _n += sizeof(long)-(_n&(sizeof(long)-1)); \
if (zmalloc_thread_safe) { \ if (zmalloc_thread_safe) { \
pthread_mutex_lock(&used_memory_mutex); \ pthread_mutex_lock(&used_memory_mutex); \
used_memory += _n; \ used_memory += _n; \
...@@ -50,7 +52,9 @@ ...@@ -50,7 +52,9 @@
} \ } \
} while(0) } while(0)
#define decrement_used_memory(_n) do { \ #define decrement_used_memory(__n) do { \
size_t _n = (__n); \
if (_n&(sizeof(long)-1)) _n += sizeof(long)-(_n&(sizeof(long)-1)); \
if (zmalloc_thread_safe) { \ if (zmalloc_thread_safe) { \
pthread_mutex_lock(&used_memory_mutex); \ pthread_mutex_lock(&used_memory_mutex); \
used_memory -= _n; \ used_memory -= _n; \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册