From e1ec64aaee2ca31ef31b9eb494ef63d0e89f7ea4 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Fri, 28 Apr 2006 21:39:38 +0000 Subject: [PATCH] rmutex_lock etc.: caller supplies thread id --- include/ldap_pvt_thread.h | 9 ++++++--- libraries/libldap_r/rmutex.c | 30 ++++++++++++------------------ libraries/libldap_r/threads.c | 10 ++++++---- servers/slapd/overlays/accesslog.c | 4 ++-- 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/include/ldap_pvt_thread.h b/include/ldap_pvt_thread.h index 76a371ebf5..c5db79d2cf 100644 --- a/include/ldap_pvt_thread.h +++ b/include/ldap_pvt_thread.h @@ -130,13 +130,16 @@ LDAP_F( int ) ldap_pvt_thread_rmutex_destroy LDAP_P(( ldap_pvt_thread_rmutex_t *rmutex )); LDAP_F( int ) -ldap_pvt_thread_rmutex_lock LDAP_P(( ldap_pvt_thread_rmutex_t *rmutex )); +ldap_pvt_thread_rmutex_lock LDAP_P(( ldap_pvt_thread_rmutex_t *rmutex, + ldap_pvt_thread_t owner)); LDAP_F( int ) -ldap_pvt_thread_rmutex_trylock LDAP_P(( ldap_pvt_thread_rmutex_t *rmutex )); +ldap_pvt_thread_rmutex_trylock LDAP_P(( ldap_pvt_thread_rmutex_t *rmutex, + ldap_pvt_thread_t owner)); LDAP_F( int ) -ldap_pvt_thread_rmutex_unlock LDAP_P(( ldap_pvt_thread_rmutex_t *rmutex )); +ldap_pvt_thread_rmutex_unlock LDAP_P(( ldap_pvt_thread_rmutex_t *rmutex, + ldap_pvt_thread_t owner)); LDAP_F( ldap_pvt_thread_t ) ldap_pvt_thread_self LDAP_P(( void )); diff --git a/libraries/libldap_r/rmutex.c b/libraries/libldap_r/rmutex.c index eb04f5674d..98529e42e0 100644 --- a/libraries/libldap_r/rmutex.c +++ b/libraries/libldap_r/rmutex.c @@ -102,10 +102,10 @@ ldap_pvt_thread_rmutex_destroy( ldap_pvt_thread_rmutex_t *rmutex ) return 0; } -int ldap_pvt_thread_rmutex_lock( ldap_pvt_thread_rmutex_t *rmutex ) +int ldap_pvt_thread_rmutex_lock( ldap_pvt_thread_rmutex_t *rmutex, + ldap_pvt_thread_t owner ) { struct ldap_int_thread_rmutex_s *rm; - ldap_pvt_thread_t tid; assert( rmutex != NULL ); rm = *rmutex; @@ -121,11 +121,9 @@ int ldap_pvt_thread_rmutex_lock( ldap_pvt_thread_rmutex_t *rmutex ) assert( rm->ltrm_depth >= 0 ); assert( rm->ltrm_waits >= 0 ); - tid = ldap_pvt_thread_self(); - if( rm->ltrm_depth > 0 ) { /* already locked */ - if ( !ldap_pvt_thread_equal( rm->ltrm_owner, tid )) { + if ( !ldap_pvt_thread_equal( rm->ltrm_owner, owner )) { rm->ltrm_waits++; do { ldap_pvt_thread_cond_wait( &rm->ltrm_cond, @@ -134,10 +132,10 @@ int ldap_pvt_thread_rmutex_lock( ldap_pvt_thread_rmutex_t *rmutex ) rm->ltrm_waits--; assert( rm->ltrm_waits >= 0 ); - rm->ltrm_owner = tid; + rm->ltrm_owner = owner; } } else { - rm->ltrm_owner = tid; + rm->ltrm_owner = owner; } rm->ltrm_depth++; @@ -147,10 +145,10 @@ int ldap_pvt_thread_rmutex_lock( ldap_pvt_thread_rmutex_t *rmutex ) return 0; } -int ldap_pvt_thread_rmutex_trylock( ldap_pvt_thread_rmutex_t *rmutex ) +int ldap_pvt_thread_rmutex_trylock( ldap_pvt_thread_rmutex_t *rmutex, + ldap_pvt_thread_t owner ) { struct ldap_int_thread_rmutex_s *rm; - ldap_pvt_thread_t tid; assert( rmutex != NULL ); rm = *rmutex; @@ -166,15 +164,13 @@ int ldap_pvt_thread_rmutex_trylock( ldap_pvt_thread_rmutex_t *rmutex ) assert( rm->ltrm_depth >= 0 ); assert( rm->ltrm_waits >= 0 ); - tid = ldap_pvt_thread_self(); - if( rm->ltrm_depth > 0 ) { - if ( !ldap_pvt_thread_equal( tid, rm->ltrm_owner )) { + if ( !ldap_pvt_thread_equal( owner, rm->ltrm_owner )) { ldap_pvt_thread_mutex_unlock( &rm->ltrm_mutex ); return LDAP_PVT_THREAD_EBUSY; } } else { - rm->ltrm_owner = tid; + rm->ltrm_owner = owner; } rm->ltrm_depth++; @@ -184,10 +180,10 @@ int ldap_pvt_thread_rmutex_trylock( ldap_pvt_thread_rmutex_t *rmutex ) return 0; } -int ldap_pvt_thread_rmutex_unlock( ldap_pvt_thread_rmutex_t *rmutex ) +int ldap_pvt_thread_rmutex_unlock( ldap_pvt_thread_rmutex_t *rmutex, + ldap_pvt_thread_t owner ) { struct ldap_int_thread_rmutex_s *rm; - ldap_pvt_thread_t tid; assert( rmutex != NULL ); rm = *rmutex; @@ -200,9 +196,7 @@ int ldap_pvt_thread_rmutex_unlock( ldap_pvt_thread_rmutex_t *rmutex ) ldap_pvt_thread_mutex_lock( &rm->ltrm_mutex ); - tid = ldap_pvt_thread_self(); - - if( !ldap_pvt_thread_equal( tid, rm->ltrm_owner )) { + if( !ldap_pvt_thread_equal( owner, rm->ltrm_owner )) { ldap_pvt_thread_mutex_unlock( &rm->ltrm_mutex ); return LDAP_PVT_THREAD_EINVAL; } diff --git a/libraries/libldap_r/threads.c b/libraries/libldap_r/threads.c index c810ad56be..b562a87d57 100644 --- a/libraries/libldap_r/threads.c +++ b/libraries/libldap_r/threads.c @@ -39,6 +39,7 @@ int ldap_pvt_thread_initialize( void ) int rc; static int init = 0; ldap_pvt_thread_rmutex_t rm; + ldap_pvt_thread_t tid; /* we only get one shot at this */ if( init++ ) return -1; @@ -53,10 +54,11 @@ int ldap_pvt_thread_initialize( void ) /* kludge to pull symbol definitions in */ ldap_pvt_thread_rmutex_init( &rm ); - ldap_pvt_thread_rmutex_lock( &rm ); - ldap_pvt_thread_rmutex_trylock( &rm ); - ldap_pvt_thread_rmutex_unlock( &rm ); - ldap_pvt_thread_rmutex_unlock( &rm ); + tid = ldap_pvt_thread_self(); + ldap_pvt_thread_rmutex_lock( &rm, tid ); + ldap_pvt_thread_rmutex_trylock( &rm, tid ); + ldap_pvt_thread_rmutex_unlock( &rm, tid ); + ldap_pvt_thread_rmutex_unlock( &rm, tid ); ldap_pvt_thread_rmutex_destroy( &rm ); return 0; diff --git a/servers/slapd/overlays/accesslog.c b/servers/slapd/overlays/accesslog.c index eccecd3a47..1630dcc518 100644 --- a/servers/slapd/overlays/accesslog.c +++ b/servers/slapd/overlays/accesslog.c @@ -934,7 +934,7 @@ static int accesslog_response(Operation *op, SlapReply *rs) { ldap_pvt_thread_mutex_lock( &li->li_log_mutex ); old = li->li_old; li->li_old = NULL; - ldap_pvt_thread_rmutex_unlock( &li->li_op_rmutex ); + ldap_pvt_thread_rmutex_unlock( &li->li_op_rmutex, op->o_tid ); } if ( li->li_success && rs->sr_err != LDAP_SUCCESS ) @@ -1253,7 +1253,7 @@ accesslog_op_mod( Operation *op, SlapReply *rs ) log_info *li = on->on_bi.bi_private; if ( li->li_ops & LOG_OP_WRITES ) { - ldap_pvt_thread_rmutex_lock( &li->li_op_rmutex ); + ldap_pvt_thread_rmutex_lock( &li->li_op_rmutex, op->o_tid ); if ( li->li_oldf && ( op->o_tag == LDAP_REQ_DELETE || op->o_tag == LDAP_REQ_MODIFY )) { int rc; -- 2.39.5