From 29ba62220dfd06d95f6c10bf3a43c2c2e12c5ed5 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Thu, 13 Aug 2009 23:42:53 +0200 Subject: [PATCH] update lock manager to get better traces --- bacula/src/lib/lockmgr.c | 15 ++++++++------- bacula/src/lib/lockmgr.h | 21 +++++++++++++++------ bacula/src/lib/rwlock.c | 4 ++-- bacula/technotes | 1 + 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/bacula/src/lib/lockmgr.c b/bacula/src/lib/lockmgr.c index 9cf9649c50..f8876e3bbc 100644 --- a/bacula/src/lib/lockmgr.c +++ b/bacula/src/lib/lockmgr.c @@ -637,13 +637,14 @@ int lmgr_mutex_unlock(pthread_mutex_t *m, const char *file, int line) /* TODO: check this */ int lmgr_cond_wait(pthread_cond_t *cond, - pthread_mutex_t *mutex) + pthread_mutex_t *mutex, + const char *file, int line) { int ret; lmgr_thread_t *self = lmgr_get_thread_info(); - self->do_V(mutex); + self->do_V(mutex, file, line); ret = pthread_cond_wait(cond, mutex); - self->pre_P(mutex); + self->pre_P(mutex, file, line); self->post_P(); return ret; } @@ -655,10 +656,10 @@ int lmgr_cond_wait(pthread_cond_t *cond, * pthread_mutex_lock(m); * lmgr_post_lock(m); */ -void lmgr_pre_lock(void *m) +void lmgr_pre_lock(void *m, const char *file, int line) { lmgr_thread_t *self = lmgr_get_thread_info(); - self->pre_P(m); + self->pre_P(m, file, line); } /* @@ -673,10 +674,10 @@ void lmgr_post_lock() /* * Do directly pre_P and post_P (used by trylock) */ -void lmgr_do_lock(void *m) +void lmgr_do_lock(void *m, const char *file, int line) { lmgr_thread_t *self = lmgr_get_thread_info(); - self->pre_P(m); + self->pre_P(m, file, line); self->post_P(); } diff --git a/bacula/src/lib/lockmgr.h b/bacula/src/lib/lockmgr.h index 83d9b3c879..173c905372 100644 --- a/bacula/src/lib/lockmgr.h +++ b/bacula/src/lib/lockmgr.h @@ -47,7 +47,8 @@ void lmgr_v(pthread_mutex_t *m); /* Not yet working */ int lmgr_cond_wait(pthread_cond_t *cond, - pthread_mutex_t *mutex); + pthread_mutex_t *mutex, + const char *file="*unknown*", int line=0); /* Replacement of pthread_mutex_lock() */ int lmgr_mutex_lock(pthread_mutex_t *m, @@ -60,10 +61,18 @@ int lmgr_mutex_unlock(pthread_mutex_t *m, /* * Use them when you want use your lock yourself (ie rwlock) */ -void lmgr_pre_lock(void *m); /* Call before requesting the lock */ -void lmgr_post_lock(); /* Call after getting it */ -void lmgr_do_lock(void *m); /* Same as pre+post lock */ -void lmgr_do_unlock(void *m); /* Call just before releasing the lock */ + +/* Call before requesting the lock */ +void lmgr_pre_lock(void *m, const char *file="*unknown*", int line=0); + +/* Call after getting it */ +void lmgr_post_lock(); + +/* Same as pre+post lock */ +void lmgr_do_lock(void *m, const char *file="*unknown*", int line=0); + +/* Call just before releasing the lock */ +void lmgr_do_unlock(void *m); /* * Each thread have to call this function to put a lmgr_thread_t object @@ -119,7 +128,7 @@ int lmgr_thread_create(pthread_t *thread, # define V(x) lmgr_mutex_unlock(&(x), __FILE__, __LINE__) # define pthread_mutex_lock(x) lmgr_mutex_lock(x, __FILE__, __LINE__) # define pthread_mutex_unlock(x) lmgr_mutex_unlock(x, __FILE__, __LINE__) -# define pthread_cond_wait(x,y) lmgr_cond_wait(x,y) +# define pthread_cond_wait(x,y) lmgr_cond_wait(x,y, __FILE__, __LINE__) # define pthread_create(a, b, c, d) lmgr_thread_create(a,b,c,d) #endif diff --git a/bacula/src/lib/rwlock.c b/bacula/src/lib/rwlock.c index 908d5c3764..e91b9eab37 100644 --- a/bacula/src/lib/rwlock.c +++ b/bacula/src/lib/rwlock.c @@ -233,7 +233,7 @@ int rwl_writelock(brwlock_t *rwl) pthread_mutex_unlock(&rwl->mutex); return 0; } - lmgr_pre_lock(rwl); + lmgr_pre_lock(rwl, __FILE__, __LINE__); if (rwl->w_active || rwl->r_active > 0) { rwl->w_wait++; /* indicate that we are waiting */ pthread_cleanup_push(rwl_write_release, (void *)rwl); @@ -278,7 +278,7 @@ int rwl_writetrylock(brwlock_t *rwl) } else { rwl->w_active = 1; /* we are running */ rwl->writer_id = pthread_self(); /* save writer thread's id */ - lmgr_do_lock(rwl); + lmgr_do_lock(rwl, __FILE__, __LINE__); } stat2 = pthread_mutex_unlock(&rwl->mutex); return (stat == 0 ? stat2 : stat); diff --git a/bacula/technotes b/bacula/technotes index 16441d7524..ed456455f6 100644 --- a/bacula/technotes +++ b/bacula/technotes @@ -3,6 +3,7 @@ General: 13Aug09 +ebl update lock manager to display file:line all the time kes Make SD lock tracing work again. Has not worked for some time. ebl bat: Add a re-run button on job info page, that allows to run the selected job with the same properties (level, pool, -- 2.39.5