Skip to content
This repository has been archived by the owner on Feb 20, 2021. It is now read-only.

Commit

Permalink
RejoinCOWPages and background threads should be synchronized (part 2)
Browse files Browse the repository at this point in the history
  • Loading branch information
enricogior committed Jun 22, 2015
1 parent 87e43c5 commit 3935ffb
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/bio.c
Expand Up @@ -158,9 +158,7 @@ void *bioProcessBackgroundJobs(void *arg) {
// needs much rework. Cancellability requires a shared event.
#endif

WIN32_ONLY(WorkerThread_EnterSafeMode());
pthread_mutex_lock(&bio_mutex[type]);
WIN32_ONLY(WorkerThread_ExitSafeMode());

/* Block SIGALRM so we are sure that only the main thread will
* receive the watchdog signal. */
Expand All @@ -177,7 +175,9 @@ void *bioProcessBackgroundJobs(void *arg) {
if (listLength(bio_jobs[type]) == 0) {
WIN32_ONLY(WorkerThread_EnterSafeMode());
pthread_cond_wait(&bio_condvar[type],&bio_mutex[type]);
WIN32_ONLY(pthread_mutex_unlock(&bio_mutex[type]));
WIN32_ONLY(WorkerThread_ExitSafeMode());
WIN32_ONLY(pthread_mutex_lock(&bio_mutex[type]));
continue;
}
/* Pop the job from the queue. */
Expand All @@ -199,9 +199,7 @@ void *bioProcessBackgroundJobs(void *arg) {

/* Lock again before reiterating the loop, if there are no longer
* jobs to process we'll block again in pthread_cond_wait(). */
WIN32_ONLY(WorkerThread_EnterSafeMode());
pthread_mutex_lock(&bio_mutex[type]);
WIN32_ONLY(WorkerThread_ExitSafeMode());
listDelNode(bio_jobs[type],ln);
bio_pending[type]--;
}
Expand Down

0 comments on commit 3935ffb

Please sign in to comment.