Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
6eb51bf1
Commit
6eb51bf1
authored
May 09, 2017
by
antirez
Browse files
zmalloc.c: remove thread safe mode, it's the default way.
parent
9390c384
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/server.c
View file @
6eb51bf1
...
...
@@ -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
);
...
...
src/zmalloc.c
View file @
6eb51bf1
...
...
@@ -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
;
}
...
...
src/zmalloc.h
View file @
6eb51bf1
...
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment