killMainThread -> killServerThreads

Former-commit-id: 0fea781f8f0218c5475890a395c49bd7e4faa03f
This commit is contained in:
christianEQ 2021-01-28 23:57:19 +00:00
parent 67d6665795
commit 011b69e9a6
3 changed files with 11 additions and 6 deletions

View File

@ -1671,8 +1671,13 @@ int memtest_test_linux_anonymous_maps(void) {
} }
#endif /* HAVE_PROC_MAPS */ #endif /* HAVE_PROC_MAPS */
static void killMainThread(void) { static void killServerThreads(void) {
int err; int err;
for (int i = 0; i < cserver.cthreads; i++) {
if (g_pserver->rgthread[i] != pthread_self()) {
pthread_cancel(g_pserver->rgthread[i]);
}
}
if (pthread_self() != cserver.main_thread_id && pthread_cancel(cserver.main_thread_id) == 0) { if (pthread_self() != cserver.main_thread_id && pthread_cancel(cserver.main_thread_id) == 0) {
if ((err = pthread_join(cserver.main_thread_id,NULL)) != 0) { if ((err = pthread_join(cserver.main_thread_id,NULL)) != 0) {
serverLog(LL_WARNING, "main thread can not be joined: %s", strerror(err)); serverLog(LL_WARNING, "main thread can not be joined: %s", strerror(err));
@ -1687,7 +1692,7 @@ static void killMainThread(void) {
* Currently Redis does this only on crash (for instance on SIGSEGV) in order * Currently Redis does this only on crash (for instance on SIGSEGV) in order
* to perform a fast memory check without other threads messing with memory. */ * to perform a fast memory check without other threads messing with memory. */
void killThreads(void) { void killThreads(void) {
killMainThread(); killServerThreads();
bioKillThreads(); bioKillThreads();
} }

View File

@ -5990,21 +5990,20 @@ int main(int argc, char **argv) {
setOOMScoreAdj(-1); setOOMScoreAdj(-1);
serverAssert(cserver.cthreads > 0 && cserver.cthreads <= MAX_EVENT_LOOPS); serverAssert(cserver.cthreads > 0 && cserver.cthreads <= MAX_EVENT_LOOPS);
pthread_t rgthread[MAX_EVENT_LOOPS];
pthread_attr_t tattr; pthread_attr_t tattr;
pthread_attr_init(&tattr); pthread_attr_init(&tattr);
pthread_attr_setstacksize(&tattr, 1 << 23); // 8 MB pthread_attr_setstacksize(&tattr, 1 << 23); // 8 MB
for (int iel = 0; iel < cserver.cthreads; ++iel) for (int iel = 0; iel < cserver.cthreads; ++iel)
{ {
pthread_create(rgthread + iel, &tattr, workerThreadMain, (void*)((int64_t)iel)); pthread_create(g_pserver->rgthread + iel, &tattr, workerThreadMain, (void*)((int64_t)iel));
if (cserver.fThreadAffinity) if (cserver.fThreadAffinity)
{ {
#ifdef __linux__ #ifdef __linux__
cpu_set_t cpuset; cpu_set_t cpuset;
CPU_ZERO(&cpuset); CPU_ZERO(&cpuset);
CPU_SET(iel + cserver.threadAffinityOffset, &cpuset); CPU_SET(iel + cserver.threadAffinityOffset, &cpuset);
if (pthread_setaffinity_np(rgthread[iel], sizeof(cpu_set_t), &cpuset) == 0) if (pthread_setaffinity_np(g_pserver->rgthread[iel], sizeof(cpu_set_t), &cpuset) == 0)
{ {
serverLog(LOG_INFO, "Binding thread %d to cpu %d", iel, iel + cserver.threadAffinityOffset + 1); serverLog(LOG_INFO, "Binding thread %d to cpu %d", iel, iel + cserver.threadAffinityOffset + 1);
} }
@ -6024,7 +6023,7 @@ int main(int argc, char **argv) {
this is so that all worker threads are orthogonal in their startup/shutdown */ this is so that all worker threads are orthogonal in their startup/shutdown */
void *pvRet; void *pvRet;
for (int iel = 0; iel < cserver.cthreads; ++iel) for (int iel = 0; iel < cserver.cthreads; ++iel)
pthread_join(rgthread[iel], &pvRet); pthread_join(g_pserver->rgthread[iel], &pvRet);
return 0; return 0;
} }

View File

@ -1488,6 +1488,7 @@ struct redisServer {
::dict *orig_commands; /* Command table before command renaming. */ ::dict *orig_commands; /* Command table before command renaming. */
struct redisServerThreadVars rgthreadvar[MAX_EVENT_LOOPS]; struct redisServerThreadVars rgthreadvar[MAX_EVENT_LOOPS];
pthread_t rgthread[MAX_EVENT_LOOPS];
std::atomic<unsigned int> lruclock; /* Clock for LRU eviction */ std::atomic<unsigned int> lruclock; /* Clock for LRU eviction */
std::atomic<int> shutdown_asap; /* SHUTDOWN needed ASAP */ std::atomic<int> shutdown_asap; /* SHUTDOWN needed ASAP */