mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-02-17 14:00:30 +08:00
rmutex_lock etc.: caller supplies thread id
This commit is contained in:
parent
ec4c74f7e0
commit
e1ec64aaee
@ -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 ));
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user