MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / bioInit

Function bioInit

src/bio.cpp:95–128  ·  view source on GitHub ↗

Initialize the background system, spawning the thread. */

Source from the content-addressed store, hash-verified

93
94/* Initialize the background system, spawning the thread. */
95void bioInit(void) {
96 pthread_attr_t attr;
97 pthread_t thread;
98 size_t stacksize;
99 int j;
100
101 /* Initialization of state vars and objects */
102 for (j = 0; j < BIO_NUM_OPS; j++) {
103 serverAssert(pthread_mutex_init(&bio_mutex[j],NULL) == 0);
104 serverAssert(pthread_cond_init(&bio_newjob_cond[j],NULL) == 0);
105 serverAssert(pthread_cond_init(&bio_step_cond[j],NULL) == 0);
106 bio_jobs[j] = listCreate();
107 bio_pending[j] = 0;
108 }
109
110 /* Set the stack size as by default it may be small in some system */
111 pthread_attr_init(&attr);
112 pthread_attr_getstacksize(&attr,&stacksize);
113 if (!stacksize) stacksize = 1; /* The world is full of Solaris Fixes */
114 while (stacksize < REDIS_THREAD_STACK_SIZE) stacksize *= 2;
115 pthread_attr_setstacksize(&attr, stacksize);
116
117 /* Ready to spawn our threads. We use the single argument the thread
118 * function accepts in order to pass the job ID the thread is
119 * responsible of. */
120 for (j = 0; j < BIO_NUM_OPS; j++) {
121 void *arg = (void*)(unsigned long) j;
122 if (pthread_create(&thread,&attr,bioProcessBackgroundJobs,arg) != 0) {
123 serverLog(LL_WARNING,"Fatal: Can't initialize Background Jobs.");
124 exit(1);
125 }
126 bio_threads[j] = thread;
127 }
128}
129
130void bioSubmitJob(int type, struct bio_job *job) {
131 job->time = time(NULL);

Callers 1

InitServerLastFunction · 0.85

Calls 3

listCreateFunction · 0.85
serverLogFunction · 0.85
pthread_createFunction · 0.50

Tested by

no test coverage detected