From: Eric Bollengier Date: Wed, 9 Dec 2009 08:01:51 +0000 (+0100) Subject: Make pthread_mutex_init/destroy compatible with bthread_mutex_t X-Git-Tag: Release-5.0.0~169^2~2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=accefd1d2da61c0f382c98c30a74223d648632e1;p=bacula%2Fbacula Make pthread_mutex_init/destroy compatible with bthread_mutex_t --- diff --git a/bacula/src/lib/lockmgr.c b/bacula/src/lib/lockmgr.c index 24f6aa2c58..9315c4fb10 100644 --- a/bacula/src/lib/lockmgr.c +++ b/bacula/src/lib/lockmgr.c @@ -47,7 +47,7 @@ With dynamic creation, you can use: bthread_mutex_t mutex; - pthread_mutex_init(&mutex); // you can also use bthread_mutex_init() + pthread_mutex_init(&mutex); bthread_mutex_set_priority(&mutex, 10); pthread_mutex_destroy(&mutex); @@ -688,7 +688,7 @@ void bthread_mutex_set_priority(bthread_mutex_t *m, int prio) /* * Replacement for pthread_mutex_init() */ -int bthread_mutex_init(bthread_mutex_t *m, const pthread_mutexattr_t *attr) +int pthread_mutex_init(bthread_mutex_t *m, const pthread_mutexattr_t *attr) { m->priority = 0; return pthread_mutex_init(&m->mutex, attr); @@ -697,28 +697,11 @@ int bthread_mutex_init(bthread_mutex_t *m, const pthread_mutexattr_t *attr) /* * Replacement for pthread_mutex_destroy() */ -int bthread_mutex_destroy(bthread_mutex_t *m) +int pthread_mutex_destroy(bthread_mutex_t *m) { return pthread_mutex_destroy(&m->mutex); } -/* - * Replacement for pthread_mutex_init() for pthread_mutex_t - */ -int bthread_mutex_init(pthread_mutex_t *m, const pthread_mutexattr_t *attr) -{ - return pthread_mutex_init(m, attr); -} - -/* - * Replacement for pthread_mutex_destroy() for pthread_mutex_t - */ -int bthread_mutex_destroy(pthread_mutex_t *m) -{ - return pthread_mutex_destroy(m); -} - - /* * Replacement for pthread_mutex_lock() * Returns always ok @@ -1106,10 +1089,13 @@ int main(int argc, char **argv) void *ret=NULL; lmgr_thread_t *self; pthread_t id1, id2, id3, tab[200]; + bthread_mutex_t bmutex1; + pthread_mutex_t pmutex2; my_prog = argv[0]; use_undertaker = false; lmgr_init_thread(); + self = lmgr_get_thread_info(); if (argc == 2) { /* do priority check */ P(mutex_p2); /* not permited */ @@ -1119,6 +1105,18 @@ int main(int argc, char **argv) return 0; } + pthread_mutex_init(&bmutex1, NULL); + bthread_mutex_set_priority(&bmutex1, 10); + + pthread_mutex_init(&pmutex2, NULL); + P(bmutex1); + ok(self->max_priority == 10, "Check self max_priority"); + P(pmutex2); + ok(bmutex1.priority == 10, "Check bmutex_set_priority()"); + V(pmutex2); + V(bmutex1); + ok(self->max_priority == 0, "Check self max_priority"); + pthread_create(&id1, NULL, self_lock, NULL); sleep(2); ok(lmgr_detect_deadlock(), "Check self deadlock"); @@ -1203,7 +1201,6 @@ int main(int argc, char **argv) pthread_join(id3, &ret); ok(ret != 0, "Check for priority segfault"); - self = lmgr_get_thread_info(); P(mutex_p1); ok(self->max_priority == 1, "Check max_priority 1/4"); P(mutex_p2); diff --git a/bacula/src/lib/lockmgr.h b/bacula/src/lib/lockmgr.h index c7a9afeec0..cd94decb36 100644 --- a/bacula/src/lib/lockmgr.h +++ b/bacula/src/lib/lockmgr.h @@ -102,13 +102,11 @@ void lmgr_do_lock(void *m, int prio=0, /* Call just before releasing the lock */ void lmgr_do_unlock(void *m); -int bthread_mutex_init(bthread_mutex_t *m, const pthread_mutexattr_t *attr); -int bthread_mutex_destroy(bthread_mutex_t *m); -void bthread_mutex_set_priority(bthread_mutex_t *m, int prio); +/* We use C++ mangling to make integration eaysier */ +int pthread_mutex_init(bthread_mutex_t *m, const pthread_mutexattr_t *attr); +int pthread_mutex_destroy(bthread_mutex_t *m); -/* init/destroy for real pthread_mutex_t object */ -int bthread_mutex_init(pthread_mutex_t *m, const pthread_mutexattr_t *attr); -int bthread_mutex_destroy(pthread_mutex_t *m); +void bthread_mutex_set_priority(bthread_mutex_t *m, int prio); /* * Each thread have to call this function to put a lmgr_thread_t object @@ -178,8 +176,6 @@ int lmgr_thread_create(pthread_t *thread, # define pthread_mutex_unlock(x) bthread_mutex_unlock(x) # define pthread_cond_wait(x,y) bthread_cond_wait(x,y) # define pthread_cond_timedwait(x,y,z) bthread_cond_timedwait(x,y,z) -# define pthread_mutex_init(x,y) bthread_mutex_init(x,y) -# define pthread_mutex_destroy(x) bthread_mutex_destroy(x) #endif #else /* _USE_LOCKMGR */ @@ -194,8 +190,6 @@ 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_init(a,b) pthread_mutex_init(a,b) -# define bthread_mutex_destroy(a) pthread_mutex_destroy(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)