From e168c79710a74f987883b17a24f17e327d88917b Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Wed, 9 Dec 2009 09:20:58 +0100 Subject: [PATCH] Add Macro BTHREAD_MUTEX_PRIORITY(p) and lib/mutex_list.h to manage locks --- bacula/src/lib/lockmgr.h | 40 +++++++++++++++++++---------------- bacula/src/lib/mutex_list.h | 42 +++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 18 deletions(-) create mode 100644 bacula/src/lib/mutex_list.h diff --git a/bacula/src/lib/lockmgr.h b/bacula/src/lib/lockmgr.h index cd94decb36..afce8bd180 100644 --- a/bacula/src/lib/lockmgr.h +++ b/bacula/src/lib/lockmgr.h @@ -154,14 +154,15 @@ int lmgr_thread_create(pthread_t *thread, * Define _LOCKMGR_COMPLIANT to use real pthread functions */ -#define BTHREAD_MUTEX_NO_PRIORITY {PTHREAD_MUTEX_INITIALIZER, 0} -#define BTHREAD_MUTEX_PRIORITY_1 {PTHREAD_MUTEX_INITIALIZER, 1} -#define BTHREAD_MUTEX_PRIORITY_2 {PTHREAD_MUTEX_INITIALIZER, 2} -#define BTHREAD_MUTEX_PRIORITY_3 {PTHREAD_MUTEX_INITIALIZER, 3} -#define BTHREAD_MUTEX_PRIORITY_4 {PTHREAD_MUTEX_INITIALIZER, 4} -#define BTHREAD_MUTEX_INITIALIZER BTHREAD_MUTEX_NO_PRIORITY +#define BTHREAD_MUTEX_PRIORITY(p) {PTHREAD_MUTEX_INITIALIZER, p} +#define BTHREAD_MUTEX_NO_PRIORITY {PTHREAD_MUTEX_INITIALIZER, 0} +#define BTHREAD_MUTEX_PRIORITY_1 {PTHREAD_MUTEX_INITIALIZER, 1} +#define BTHREAD_MUTEX_PRIORITY_2 {PTHREAD_MUTEX_INITIALIZER, 2} +#define BTHREAD_MUTEX_PRIORITY_3 {PTHREAD_MUTEX_INITIALIZER, 3} +#define BTHREAD_MUTEX_PRIORITY_4 {PTHREAD_MUTEX_INITIALIZER, 4} +#define BTHREAD_MUTEX_INITIALIZER BTHREAD_MUTEX_NO_PRIORITY #define bthread_mutex_lock(x) bthread_mutex_lock_p(x, __FILE__, __LINE__) -#define bthread_mutex_unlock(x) bthread_mutex_unlock_p +#define bthread_mutex_unlock(x) bthread_mutex_unlock_p(x, __FILE__, __LINE__) #define bthread_cond_wait(x,y) bthread_cond_wait_p(x,y, __FILE__, __LINE__) #define bthread_cond_timedwait(x,y,z) bthread_cond_timedwait_p(x,y,z, __FILE__, __LINE__) @@ -190,19 +191,22 @@ int lmgr_thread_create(pthread_t *thread, # define lmgr_do_unlock(m) # define lmgr_cleanup_main() # define bthread_mutex_set_priority(a) -# define bthread_mutex_lock(a) pthread_mutex_lock(a) -# define bthread_mutex_unlock(a) pthread_mutex_unlock(a) -# define lmgr_cond_wait(a,b) pthread_cond_wait(a,b) -# define lmgr_cond_timedwait(a,b,c) pthread_cond_timedwait(a,b,c) -# define bthread_mutex_t pthread_mutex_t +# define bthread_mutex_lock(a) pthread_mutex_lock(a) +# define bthread_mutex_unlock(a) pthread_mutex_unlock(a) +# define lmgr_cond_wait(a,b) pthread_cond_wait(a,b) +# define lmgr_cond_timedwait(a,b,c) pthread_cond_timedwait(a,b,c) +# define bthread_mutex_t pthread_mutex_t # define P(x) lmgr_p(&(x)) # define V(x) lmgr_v(&(x)) -# define BTHREAD_MUTEX_NO_PRIORITY PTHREAD_MUTEX_INITIALIZER -# define BTHREAD_MUTEX_PRIORITY_1 PTHREAD_MUTEX_INITIALIZER -# define BTHREAD_MUTEX_PRIORITY_2 PTHREAD_MUTEX_INITIALIZER -# define BTHREAD_MUTEX_PRIORITY_3 PTHREAD_MUTEX_INITIALIZER -# define BTHREAD_MUTEX_PRIORITY_4 PTHREAD_MUTEX_INITIALIZER -# define BTHREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER +# define BTHREAD_MUTEX_PRIORITY(p) PTHREAD_MUTEX_INITIALIZER +# define BTHREAD_MUTEX_NO_PRIORITY PTHREAD_MUTEX_INITIALIZER +# define BTHREAD_MUTEX_PRIORITY_1 PTHREAD_MUTEX_INITIALIZER +# define BTHREAD_MUTEX_PRIORITY_2 PTHREAD_MUTEX_INITIALIZER +# define BTHREAD_MUTEX_PRIORITY_3 PTHREAD_MUTEX_INITIALIZER +# define BTHREAD_MUTEX_PRIORITY_4 PTHREAD_MUTEX_INITIALIZER +# define BTHREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER #endif /* _USE_LOCKMGR */ +#include "mutex_list.h" /* Manage mutex with priority in a central place */ + #endif /* _LOCKMGR_H */ diff --git a/bacula/src/lib/mutex_list.h b/bacula/src/lib/mutex_list.h new file mode 100644 index 0000000000..42d3995d6d --- /dev/null +++ b/bacula/src/lib/mutex_list.h @@ -0,0 +1,42 @@ +/* + Bacula® - The Network Backup Solution + + Copyright (C) 2009-2009 Free Software Foundation Europe e.V. + + The main author of Bacula is Kern Sibbald, with contributions from + many others, a complete list can be found in the file AUTHORS. + This program is Free Software; you can redistribute it and/or + modify it under the terms of version two of the GNU General Public + License as published by the Free Software Foundation, which is + listed in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + Bacula® is a registered trademark of Kern Sibbald. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. +*/ + +#ifndef MUTEX_LIST_H +#define MUTEX_LIST_H 1 + +/* + * Use this list to manage lock order and protect the Bacula from + * race conditions and dead locks + */ + +#define PRIO_SD_VOLUME_LIST 20 +#define PRIO_SD_DEV_ACCESS 15 +#define PRIO_SD_DEV_SPOOL 14 +#define PRIO_SD_DEV_ACQUIRE 13 + +#endif -- 2.39.5