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