diff options
author | WuYunlong <xzsyeb@126.com> | 2020-09-18 16:08:52 +0800 |
---|---|---|
committer | Oran Agra <oran@redislabs.com> | 2020-10-27 09:12:01 +0200 |
commit | 4832cf4fd695a98ecc70dc2354dd221b61cac339 (patch) | |
tree | 27f106ce531ab9ead63ba9feea463eec71a08527 | |
parent | fd610ae02535d4da9c839578faebbf4367be4e57 (diff) | |
download | redis-4832cf4fd695a98ecc70dc2354dd221b61cac339.tar.gz |
Make main thread killable so that it can be canceled at any time.
Refine comment of makeThreadKillable().
This commit can be backported to 5.0, only if we also backport 8b70cb0.
Co-authored-by: Oran Agra <oran@redislabs.com>
(cherry picked from commit 647cac5bb469171a5b97eade276335ab9c552edc)
-rw-r--r-- | src/bio.c | 5 | ||||
-rw-r--r-- | src/server.c | 9 | ||||
-rw-r--r-- | src/server.h | 1 |
3 files changed, 11 insertions, 4 deletions
@@ -168,10 +168,7 @@ void *bioProcessBackgroundJobs(void *arg) { redisSetCpuAffinity(server.bio_cpulist); - /* Make the thread killable at any time, so that bioKillThreads() - * can work reliably. */ - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); - pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); + makeThreadKillable(); pthread_mutex_lock(&bio_mutex[type]); /* Block SIGALRM so we are sure that only the main thread will diff --git a/src/server.c b/src/server.c index ed416fb4c..5face48bb 100644 --- a/src/server.c +++ b/src/server.c @@ -2798,12 +2798,21 @@ void resetServerStats(void) { server.aof_delayed_fsync = 0; } +/* Make the thread killable at any time, so that kill threads functions + * can work reliably (default cancelability type is PTHREAD_CANCEL_DEFERRED). + * Needed for pthread_cancel used by the fast memory test used by the crash report. */ +void makeThreadKillable(void) { + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); +} + void initServer(void) { int j; signal(SIGHUP, SIG_IGN); signal(SIGPIPE, SIG_IGN); setupSignalHandlers(); + makeThreadKillable(); if (server.syslog_enabled) { openlog(server.syslog_ident, LOG_PID | LOG_NDELAY | LOG_NOWAIT, diff --git a/src/server.h b/src/server.h index 66d373944..3317092a0 100644 --- a/src/server.h +++ b/src/server.h @@ -2471,6 +2471,7 @@ void xorDigest(unsigned char *digest, void *ptr, size_t len); int populateCommandTableParseFlags(struct redisCommand *c, char *strflags); void killIOThreads(void); void killThreads(void); +void makeThreadKillable(void); /* TLS stuff */ void tlsInit(void); |