From: Kurt Zeilenga Date: Fri, 16 Jun 2000 21:25:03 +0000 (+0000) Subject: Add asserts aliasing debugging purposes. X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~2605 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=35e77f88be2b354ffe93312a02a3791620ab1889;p=openldap Add asserts aliasing debugging purposes. --- diff --git a/libraries/libldap_r/rdwr.c b/libraries/libldap_r/rdwr.c index 6a43f66a18..ef90061915 100644 --- a/libraries/libldap_r/rdwr.c +++ b/libraries/libldap_r/rdwr.c @@ -80,6 +80,11 @@ ldap_pvt_thread_rdwr_destroy( ldap_pvt_thread_rdwr_t *rwlock ) ldap_pvt_thread_mutex_lock( &rw->ltrw_mutex ); + assert( rw->ltrw_w_active >= 0 ); + assert( rw->ltrw_w_wait >= 0 ); + assert( rw->ltrw_r_active >= 0 ); + assert( rw->ltrw_r_wait >= 0 ); + /* active threads? */ if( rw->ltrw_r_active > 0 || rw->ltrw_w_active > 0) { ldap_pvt_thread_mutex_unlock( &rw->ltrw_mutex ); @@ -120,6 +125,11 @@ int ldap_pvt_thread_rdwr_rlock( ldap_pvt_thread_rdwr_t *rwlock ) ldap_pvt_thread_mutex_lock( &rw->ltrw_mutex ); + assert( rw->ltrw_w_active >= 0 ); + assert( rw->ltrw_w_wait >= 0 ); + assert( rw->ltrw_r_active >= 0 ); + assert( rw->ltrw_r_wait >= 0 ); + if( rw->ltrw_w_active > 0 ) { /* writer is active */ @@ -131,6 +141,7 @@ int ldap_pvt_thread_rdwr_rlock( ldap_pvt_thread_rdwr_t *rwlock ) } while( rw->ltrw_w_active > 0 ); rw->ltrw_r_wait--; + assert( rw->ltrw_r_wait >= 0 ); } rw->ltrw_r_active++; @@ -155,6 +166,11 @@ int ldap_pvt_thread_rdwr_rtrylock( ldap_pvt_thread_rdwr_t *rwlock ) ldap_pvt_thread_mutex_lock( &rw->ltrw_mutex ); + assert( rw->ltrw_w_active >= 0 ); + assert( rw->ltrw_w_wait >= 0 ); + assert( rw->ltrw_r_active >= 0 ); + assert( rw->ltrw_r_wait >= 0 ); + if( rw->ltrw_w_active > 0) { ldap_pvt_thread_mutex_unlock( &rw->ltrw_mutex ); return LDAP_PVT_THREAD_EBUSY; @@ -184,6 +200,11 @@ int ldap_pvt_thread_rdwr_runlock( ldap_pvt_thread_rdwr_t *rwlock ) rw->ltrw_r_active--; + assert( rw->ltrw_w_active >= 0 ); + assert( rw->ltrw_w_wait >= 0 ); + assert( rw->ltrw_r_active >= 0 ); + assert( rw->ltrw_r_wait >= 0 ); + if (rw->ltrw_r_active == 0 && rw->ltrw_w_wait > 0 ) { ldap_pvt_thread_cond_signal( &rw->ltrw_write ); } @@ -208,6 +229,11 @@ int ldap_pvt_thread_rdwr_wlock( ldap_pvt_thread_rdwr_t *rwlock ) ldap_pvt_thread_mutex_lock( &rw->ltrw_mutex ); + assert( rw->ltrw_w_active >= 0 ); + assert( rw->ltrw_w_wait >= 0 ); + assert( rw->ltrw_r_active >= 0 ); + assert( rw->ltrw_r_wait >= 0 ); + if ( rw->ltrw_w_active > 0 || rw->ltrw_r_active > 0 ) { rw->ltrw_w_wait++; @@ -217,6 +243,7 @@ int ldap_pvt_thread_rdwr_wlock( ldap_pvt_thread_rdwr_t *rwlock ) } while ( rw->ltrw_w_active > 0 || rw->ltrw_r_active > 0 ); rw->ltrw_w_wait--; + assert( rw->ltrw_w_wait >= 0 ); } rw->ltrw_w_active++; @@ -241,6 +268,11 @@ int ldap_pvt_thread_rdwr_wtrylock( ldap_pvt_thread_rdwr_t *rwlock ) ldap_pvt_thread_mutex_lock( &rw->ltrw_mutex ); + assert( rw->ltrw_w_active >= 0 ); + assert( rw->ltrw_w_wait >= 0 ); + assert( rw->ltrw_r_active >= 0 ); + assert( rw->ltrw_r_wait >= 0 ); + if ( rw->ltrw_w_active > 0 || rw->ltrw_r_active > 0 ) { ldap_pvt_thread_mutex_unlock( &rw->ltrw_mutex ); return LDAP_PVT_THREAD_EBUSY; @@ -270,6 +302,11 @@ int ldap_pvt_thread_rdwr_wunlock( ldap_pvt_thread_rdwr_t *rwlock ) rw->ltrw_w_active--; + assert( rw->ltrw_w_active >= 0 ); + assert( rw->ltrw_w_wait >= 0 ); + assert( rw->ltrw_r_active >= 0 ); + assert( rw->ltrw_r_wait >= 0 ); + if (rw->ltrw_r_wait > 0) { ldap_pvt_thread_cond_broadcast( &rw->ltrw_read ); @@ -303,6 +340,10 @@ int ldap_pvt_thread_rdwr_readers(ldap_pvt_thread_rdwr_t *rwlock) assert( rw != NULL ); assert( rw->ltrw_valid == LDAP_PVT_THREAD_RDWR_VALID ); + assert( rw->ltrw_w_active >= 0 ); + assert( rw->ltrw_w_wait >= 0 ); + assert( rw->ltrw_r_active >= 0 ); + assert( rw->ltrw_r_wait >= 0 ); return( rw->ltrw_r_active ); } @@ -316,6 +357,10 @@ int ldap_pvt_thread_rdwr_writers(ldap_pvt_thread_rdwr_t *rwlock) assert( rw != NULL ); assert( rw->ltrw_valid == LDAP_PVT_THREAD_RDWR_VALID ); + assert( rw->ltrw_w_active >= 0 ); + assert( rw->ltrw_w_wait >= 0 ); + assert( rw->ltrw_r_active >= 0 ); + assert( rw->ltrw_r_wait >= 0 ); return( rw->ltrw_w_active ); } @@ -329,6 +374,10 @@ int ldap_pvt_thread_rdwr_active(ldap_pvt_thread_rdwr_t *rwlock) assert( rw != NULL ); assert( rw->ltrw_valid == LDAP_PVT_THREAD_RDWR_VALID ); + assert( rw->ltrw_w_active >= 0 ); + assert( rw->ltrw_w_wait >= 0 ); + 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));