MCPcopy Create free account
hub / github.com/F-Stack/f-stack / initThreadedIO

Function initThreadedIO

app/redis-6.2.6/src/networking.c:3510–3540  ·  view source on GitHub ↗

Initialize the data structures needed for threaded I/O. */

Source from the content-addressed store, hash-verified

3508
3509/* Initialize the data structures needed for threaded I/O. */
3510void initThreadedIO(void) {
3511 server.io_threads_active = 0; /* We start with threads not active. */
3512
3513 /* Don't spawn any thread if the user selected a single thread:
3514 * we'll handle I/O directly from the main thread. */
3515 if (server.io_threads_num == 1) return;
3516
3517 if (server.io_threads_num > IO_THREADS_MAX_NUM) {
3518 serverLog(LL_WARNING,"Fatal: too many I/O threads configured. "
3519 "The maximum number is %d.", IO_THREADS_MAX_NUM);
3520 exit(1);
3521 }
3522
3523 /* Spawn and initialize the I/O threads. */
3524 for (int i = 0; i < server.io_threads_num; i++) {
3525 /* Things we do for all the threads including the main thread. */
3526 io_threads_list[i] = listCreate();
3527 if (i == 0) continue; /* Thread 0 is the main thread. */
3528
3529 /* Things we do only for the additional threads. */
3530 pthread_t tid;
3531 pthread_mutex_init(&io_threads_mutex[i],NULL);
3532 setIOPendingCount(i, 0);
3533 pthread_mutex_lock(&io_threads_mutex[i]); /* Thread will be stopped. */
3534 if (pthread_create(&tid,NULL,IOThreadMain,(void*)(long)i) != 0) {
3535 serverLog(LL_WARNING,"Fatal: Can't initialize IO thread.");
3536 exit(1);
3537 }
3538 io_threads[i] = tid;
3539 }
3540}
3541
3542void killIOThreads(void) {
3543 int err, j;

Callers 1

InitServerLastFunction · 0.85

Calls 5

listCreateFunction · 0.85
pthread_mutex_initFunction · 0.85
setIOPendingCountFunction · 0.85
pthread_mutex_lockFunction · 0.85
pthread_createFunction · 0.50

Tested by

no test coverage detected