diff options
author | antirez <antirez@gmail.com> | 2017-05-10 10:01:06 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2017-05-10 10:04:16 +0200 |
commit | 1f598fc2bb6975417751486405303d98246bb7bc (patch) | |
tree | a440ed56dfbd15ed1eb2375298ab1ae40c3cc0c6 /src/server.c | |
parent | de786186a5a0cd15aa86a2127647fb9c758bc405 (diff) | |
download | redis-thread-safe-context.tar.gz |
Modules TSC: use atomic var for server.unixtime.thread-safe-context
This avoids Helgrind complaining, but we are actually not using
atomicGet() to get the unixtime value for now: too many places where it
is used and given tha time_t is word-sized it should be safe in all the
archs we support as it is.
On the other hand, Helgrind, when Redis is compiled with "make helgrind"
in order to force the __sync macros, will detect the write in
updateCachedTime() as a read (because atomic functions are used) and
will not complain about races.
This commit also includes minor refactoring of mutex initializations and
a "helgrind" target in the Makefile.
Diffstat (limited to 'src/server.c')
-rw-r--r-- | src/server.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/server.c b/src/server.c index 75268b8a4..e50ec6359 100644 --- a/src/server.c +++ b/src/server.c @@ -923,7 +923,8 @@ void databasesCron(void) { * every object access, and accuracy is not needed. To access a global var is * a lot faster than calling time(NULL) */ void updateCachedTime(void) { - server.unixtime = time(NULL); + time_t unixtime = time(NULL); + atomicSet(server.unixtime,unixtime); server.mstime = mstime(); } @@ -1331,6 +1332,10 @@ void createSharedObjects(void) { void initServerConfig(void) { int j; + pthread_mutex_init(&server.next_client_id_mutex,NULL); + pthread_mutex_init(&server.lruclock_mutex,NULL); + pthread_mutex_init(&server.unixtime_mutex,NULL); + getRandomHexChars(server.runid,CONFIG_RUN_ID_SIZE); server.runid[CONFIG_RUN_ID_SIZE] = '\0'; changeReplicationId(); @@ -1423,7 +1428,6 @@ void initServerConfig(void) { server.cluster_announce_bus_port = CONFIG_DEFAULT_CLUSTER_ANNOUNCE_BUS_PORT; server.migrate_cached_sockets = dictCreate(&migrateCacheDictType,NULL); server.next_client_id = 1; /* Client IDs, start from 1 .*/ - pthread_mutex_init(&server.next_client_id_mutex,NULL); server.loading_process_events_interval_bytes = (1024*1024*2); server.lazyfree_lazy_eviction = CONFIG_DEFAULT_LAZYFREE_LAZY_EVICTION; server.lazyfree_lazy_expire = CONFIG_DEFAULT_LAZYFREE_LAZY_EXPIRE; @@ -1432,7 +1436,6 @@ void initServerConfig(void) { server.lua_time_limit = LUA_SCRIPT_TIME_LIMIT; unsigned int lruclock = getLRUClock(); - pthread_mutex_init(&server.lruclock_mutex,NULL); atomicSet(server.lruclock,lruclock); resetServerSaveParams(); |