From c8fefdb808715c12615281769b6477211f0cebc0 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sat, 15 Aug 2009 11:41:17 +0200 Subject: [PATCH] Move global acquire lock to lock by device --- bacula/src/stored/acquire.c | 6 ++---- bacula/src/stored/dev.c | 6 ++++++ bacula/src/stored/dev.h | 5 +++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/bacula/src/stored/acquire.c b/bacula/src/stored/acquire.c index 2cacabcecb..dc3b7269c3 100644 --- a/bacula/src/stored/acquire.c +++ b/bacula/src/stored/acquire.c @@ -333,8 +333,6 @@ get_out: return ok; } -static pthread_mutex_t acquire_lock = PTHREAD_MUTEX_INITIALIZER; - /* * Acquire device for writing. We permit multiple writers. * If this is the first one, we read the label. @@ -353,7 +351,7 @@ DCR *acquire_device_for_append(DCR *dcr) init_device_wait_timers(dcr); - P(acquire_lock); /* only one job at a time */ + P(dev->acquire_mutex); /* only one job at a time */ dev->dlock(); Dmsg1(100, "acquire_append device is %s\n", dev->is_tape()?"tape": (dev->is_dvd()?"DVD":"disk")); @@ -423,7 +421,7 @@ DCR *acquire_device_for_append(DCR *dcr) get_out: dcr->clear_reserved(); dev->dunlock(); - V(acquire_lock); + V(dev->acquire_mutex); return ok ? dcr : NULL; } diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index df3eaf4146..eb4679f7e2 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -256,6 +256,12 @@ init_dev(JCR *jcr, DEVRES *device) Mmsg1(dev->errmsg, _("Unable to init mutex: ERR=%s\n"), be.bstrerror(errstat)); Jmsg0(jcr, M_ERROR_TERM, 0, dev->errmsg); } + if ((errstat = pthread_mutex_init(&dev->acquire_mutex, NULL)) != 0) { + berrno be; + dev->dev_errno = errstat; + Mmsg1(dev->errmsg, _("Unable to init mutex: ERR=%s\n"), be.bstrerror(errstat)); + Jmsg0(jcr, M_ERROR_TERM, 0, dev->errmsg); + } #ifdef xxx if ((errstat = rwl_init(&dev->lock)) != 0) { berrno be; diff --git a/bacula/src/stored/dev.h b/bacula/src/stored/dev.h index 51a1b1b6ae..22734bb805 100644 --- a/bacula/src/stored/dev.h +++ b/bacula/src/stored/dev.h @@ -211,17 +211,18 @@ private: int m_fd; /* file descriptor */ int m_blocked; /* set if we must wait (i.e. change tape) */ int m_count; /* Mutex use count -- DEBUG only */ + int m_num_reserved; /* counter of device reservations */ + int32_t m_slot; /* slot loaded in drive or -1 if none */ pthread_t m_pid; /* Thread that locked -- DEBUG only */ bool m_unload; /* set when Volume must be unloaded */ bool m_load; /* set when Volume must be loaded */ - int m_num_reserved; /* counter of device reservations */ - int32_t m_slot; /* slot loaded in drive or -1 if none */ public: DEVICE * volatile swap_dev; /* Swap vol from this device */ dlist *attached_dcrs; /* attached DCR list */ pthread_mutex_t m_mutex; /* access control */ pthread_mutex_t spool_mutex; /* mutex for updating spool_size */ + pthread_mutex_t acquire_mutex; /* mutex for acquire code */ pthread_cond_t wait; /* thread wait variable */ pthread_cond_t wait_next_vol; /* wait for tape to be mounted */ pthread_t no_wait_id; /* this thread must not wait */ -- 2.39.5