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

Function bioProcessBackgroundJobs

app/redis-6.2.6/src/bio.c:167–256  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

165}
166
167void *bioProcessBackgroundJobs(void *arg) {
168 struct bio_job *job;
169 unsigned long type = (unsigned long) arg;
170 sigset_t sigset;
171
172 /* Check that the type is within the right interval. */
173 if (type >= BIO_NUM_OPS) {
174 serverLog(LL_WARNING,
175 "Warning: bio thread started with wrong type %lu",type);
176 return NULL;
177 }
178
179 switch (type) {
180 case BIO_CLOSE_FILE:
181 redis_set_thread_title("bio_close_file");
182 break;
183 case BIO_AOF_FSYNC:
184 redis_set_thread_title("bio_aof_fsync");
185 break;
186 case BIO_LAZY_FREE:
187 redis_set_thread_title("bio_lazy_free");
188 break;
189 }
190
191 redisSetCpuAffinity(server.bio_cpulist);
192
193 makeThreadKillable();
194
195 pthread_mutex_lock(&bio_mutex[type]);
196 /* Block SIGALRM so we are sure that only the main thread will
197 * receive the watchdog signal. */
198 sigemptyset(&sigset);
199 sigaddset(&sigset, SIGALRM);
200 if (pthread_sigmask(SIG_BLOCK, &sigset, NULL))
201 serverLog(LL_WARNING,
202 "Warning: can't mask SIGALRM in bio.c thread: %s", strerror(errno));
203
204 while(1) {
205 listNode *ln;
206
207 /* The loop always starts with the lock hold. */
208 if (listLength(bio_jobs[type]) == 0) {
209 pthread_cond_wait(&bio_newjob_cond[type],&bio_mutex[type]);
210 continue;
211 }
212 /* Pop the job from the queue. */
213 ln = listFirst(bio_jobs[type]);
214 job = ln->value;
215 /* It is now possible to unlock the background system as we know have
216 * a stand alone job structure to process.*/
217 pthread_mutex_unlock(&bio_mutex[type]);
218
219 /* Process the job accordingly to its type. */
220 if (type == BIO_CLOSE_FILE) {
221 close(job->fd);
222 } else if (type == BIO_AOF_FSYNC) {
223 /* The fd may be closed by main thread and reused for another
224 * socket, pipe, or file. We just ignore these errno because

Callers

nothing calls this directly

Calls 7

redisSetCpuAffinityFunction · 0.85
makeThreadKillableFunction · 0.85
pthread_mutex_lockFunction · 0.85
pthread_mutex_unlockFunction · 0.85
listDelNodeFunction · 0.85
closeFunction · 0.70
zfreeFunction · 0.70

Tested by

no test coverage detected