From: Howard Chu Date: Sat, 3 Jul 2004 16:25:30 +0000 (+0000) Subject: Additional debug tracking... X-Git-Tag: OPENDLAP_REL_ENG_2_2_MP~123 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=0305199518f774307aebe04ca8abbc702a2f8ff4;p=openldap Additional debug tracking... --- diff --git a/libraries/libldap_r/rdwr.c b/libraries/libldap_r/rdwr.c index dc9dcedc4b..b0613c0751 100644 --- a/libraries/libldap_r/rdwr.c +++ b/libraries/libldap_r/rdwr.c @@ -59,6 +59,12 @@ struct ldap_int_thread_rdwr_s { int ltrw_w_active; int ltrw_r_wait; int ltrw_w_wait; +#ifdef LDAP_RDWR_DEBUG + /* keep track of who has these locks */ +#define MAX_READERS 32 + ldap_pvt_thread_t ltrw_readers[MAX_READERS]; + ldap_pvt_thread_t ltrw_writer; +#endif }; int @@ -162,8 +168,12 @@ int ldap_pvt_thread_rdwr_rlock( ldap_pvt_thread_rdwr_t *rwlock ) assert( rw->ltrw_r_wait >= 0 ); } +#ifdef LDAP_RDWR_DEBUG + rw->ltrw_readers[rw->ltrw_r_active] = ldap_pvt_thread_self(); +#endif rw->ltrw_r_active++; + ldap_pvt_thread_mutex_unlock( &rw->ltrw_mutex ); return 0; @@ -194,6 +204,9 @@ int ldap_pvt_thread_rdwr_rtrylock( ldap_pvt_thread_rdwr_t *rwlock ) return LDAP_PVT_THREAD_EBUSY; } +#ifdef LDAP_RDWR_DEBUG + rw->ltrw_readers[rw->ltrw_r_active] = ldap_pvt_thread_self(); +#endif rw->ltrw_r_active++; ldap_pvt_thread_mutex_unlock( &rw->ltrw_mutex ); @@ -216,6 +229,22 @@ int ldap_pvt_thread_rdwr_runlock( ldap_pvt_thread_rdwr_t *rwlock ) ldap_pvt_thread_mutex_lock( &rw->ltrw_mutex ); +#ifdef LDAP_RDWR_DEBUG + /* Remove us from the list of readers */ + { int i, j; + ldap_pvt_thread_t self = ldap_pvt_thread_self(); + + for (i=0; iltrw_r_active;i++) + { + if (rw->ltrw_readers[i] == self) { + for (j=i; jltrw_r_active-1; j++) + rw->ltrw_readers[j] = rw->ltrw_readers[j+1]; + rw->ltrw_readers[j] = 0; + break; + } + } + } +#endif rw->ltrw_r_active--; assert( rw->ltrw_w_active >= 0 ); @@ -264,6 +293,9 @@ int ldap_pvt_thread_rdwr_wlock( ldap_pvt_thread_rdwr_t *rwlock ) assert( rw->ltrw_w_wait >= 0 ); } +#ifdef LDAP_RDWR_DEBUG + rw->ltrw_writer = ldap_pvt_thread_self(); +#endif rw->ltrw_w_active++; ldap_pvt_thread_mutex_unlock( &rw->ltrw_mutex ); @@ -296,6 +328,9 @@ int ldap_pvt_thread_rdwr_wtrylock( ldap_pvt_thread_rdwr_t *rwlock ) return LDAP_PVT_THREAD_EBUSY; } +#ifdef LDAP_RDWR_DEBUG + rw->ltrw_writer = ldap_pvt_thread_self(); +#endif rw->ltrw_w_active++; ldap_pvt_thread_mutex_unlock( &rw->ltrw_mutex ); @@ -332,6 +367,9 @@ int ldap_pvt_thread_rdwr_wunlock( ldap_pvt_thread_rdwr_t *rwlock ) ldap_pvt_thread_cond_signal( &rw->ltrw_write ); } +#ifdef LDAP_RDWR_DEBUG + rw->ltrw_writer = 0; +#endif ldap_pvt_thread_mutex_unlock( &rw->ltrw_mutex ); return 0; @@ -397,8 +435,8 @@ int ldap_pvt_thread_rdwr_active(ldap_pvt_thread_rdwr_t *rwlock) assert( rw->ltrw_r_active >= 0 ); assert( rw->ltrw_r_wait >= 0 ); - return(ldap_pvt_thread_rdwr_readers(rw) + - ldap_pvt_thread_rdwr_writers(rw)); + return(ldap_pvt_thread_rdwr_readers(rwlock) + + ldap_pvt_thread_rdwr_writers(rwlock)); } #endif /* LDAP_DEBUG */