From: Kern Sibbald Date: Wed, 19 Mar 2003 10:16:08 +0000 (+0000) Subject: Minor cleanup of semaphore scheduling code X-Git-Tag: Release-1.30~82 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=2ea7021fd31d1bf7273f4a727f20e91a9c2637d9;p=bacula%2Fbacula Minor cleanup of semaphore scheduling code git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@385 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/kernstodo b/bacula/kernstodo index eb15b2f1ea..b143903f8f 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -21,6 +21,8 @@ Testing to do: (painful) - ***test GetFileAttributexEx, and remove MessageBox at 335 of winservice.cpp **** For 1.30 release: +- If tape is marked read-only, then try opening it read-only rather than + failing, and remember that it cannot be written. - Refine SD waiting output: Device is being positioned > Device is being positioned for append diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index b35be631d1..c12788da50 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -54,6 +54,7 @@ extern void backup_cleanup(void); static semlock_t job_lock; static pthread_mutex_t mutex; static pthread_cond_t resource_wait; +static int waiting = 0; /* count of waiting threads */ #else /* Queue of jobs to be run */ workq_t job_wq; /* our job work queue */ @@ -248,6 +249,11 @@ static void *job_thread(void *arg) return NULL; } +/* + * Acquire the resources needed. These locks limit the + * number of jobs by each resource. We have limits on + * Jobs, Clients, Storage, and total jobs. + */ static int acquire_resource_locks(JCR *jcr) { #ifdef USE_SEMAPHORE @@ -306,8 +312,13 @@ static int acquire_resource_locks(JCR *jcr) wait: P(mutex); - /* Wait for some resource to be released */ + /* + * Wait for a resource to be released either by backoff or + * by a job terminating. + */ + waiting++; pthread_cond_wait(&resource_wait, &mutex); + waiting--; V(mutex); /* Try again */ } @@ -316,20 +327,43 @@ wait: } #ifdef USE_SEMAPHORE +/* + * We could not get all the resource locks because + * too many jobs are running, so release any locks + * we did acquire, giving others a chance to use them + * while we wait. + */ static void backoff_resource_locks(JCR *jcr, int count) { + P(mutex); switch (count) { case 3: sem_unlock(&jcr->store->sem); + /* Fall through wanted */ case 2: sem_unlock(&jcr->client->sem); + /* Fall through wanted */ case 1: sem_unlock(&jcr->job->sem); break; } + /* + * Since we released a lock, if there are any threads + * waiting, wake them up so that they can try again. + */ + if (waiting > 0) { + pthread_cond_broadcast(&resource_wait); + } + V(mutex); } #endif +/* + * This is called at the end of the job to release + * any resource limits on the number of jobs. If + * there are any other jobs waiting, we wake them + * up so that they can try again. + */ static void release_resource_locks(JCR *jcr) { #ifdef USE_SEMAPHORE @@ -338,7 +372,9 @@ static void release_resource_locks(JCR *jcr) sem_unlock(&jcr->client->sem); sem_unlock(&jcr->job->sem); sem_unlock(&job_lock); - pthread_cond_signal(&resource_wait); + if (waiting > 0) { + pthread_cond_broadcast(&resource_wait); + } V(mutex); #endif } diff --git a/bacula/src/version.h b/bacula/src/version.h index 909e06a87c..d6c3321a44 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -1,8 +1,8 @@ /* */ #define VERSION "1.30" #define VSTRING "1" -#define BDATE "17 March 2003" -#define LSMDATE "17Mar03" +#define BDATE "19 March 2003" +#define LSMDATE "19Mar03" /* Debug flags */ #define DEBUG 1