Commit 4832cf4f authored by WuYunlong's avatar WuYunlong Committed by Oran Agra
Browse files

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 8b70cb0e

.
Co-authored-by: default avatarOran Agra <oran@redislabs.com>
(cherry picked from commit 647cac5b)
parent fd610ae0
...@@ -168,10 +168,7 @@ void *bioProcessBackgroundJobs(void *arg) { ...@@ -168,10 +168,7 @@ void *bioProcessBackgroundJobs(void *arg) {
redisSetCpuAffinity(server.bio_cpulist); redisSetCpuAffinity(server.bio_cpulist);
/* Make the thread killable at any time, so that bioKillThreads() makeThreadKillable();
* can work reliably. */
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
pthread_mutex_lock(&bio_mutex[type]); pthread_mutex_lock(&bio_mutex[type]);
/* Block SIGALRM so we are sure that only the main thread will /* Block SIGALRM so we are sure that only the main thread will
......
...@@ -2798,12 +2798,21 @@ void resetServerStats(void) { ...@@ -2798,12 +2798,21 @@ void resetServerStats(void) {
server.aof_delayed_fsync = 0; 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) { void initServer(void) {
int j; int j;
signal(SIGHUP, SIG_IGN); signal(SIGHUP, SIG_IGN);
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
setupSignalHandlers(); setupSignalHandlers();
makeThreadKillable();
if (server.syslog_enabled) { if (server.syslog_enabled) {
openlog(server.syslog_ident, LOG_PID | LOG_NDELAY | LOG_NOWAIT, openlog(server.syslog_ident, LOG_PID | LOG_NDELAY | LOG_NOWAIT,
......
...@@ -2471,6 +2471,7 @@ void xorDigest(unsigned char *digest, void *ptr, size_t len); ...@@ -2471,6 +2471,7 @@ void xorDigest(unsigned char *digest, void *ptr, size_t len);
int populateCommandTableParseFlags(struct redisCommand *c, char *strflags); int populateCommandTableParseFlags(struct redisCommand *c, char *strflags);
void killIOThreads(void); void killIOThreads(void);
void killThreads(void); void killThreads(void);
void makeThreadKillable(void);
/* TLS stuff */ /* TLS stuff */
void tlsInit(void); void tlsInit(void);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment