From: Pierangelo Masarati Date: Sun, 7 Aug 2005 00:35:11 +0000 (+0000) Subject: use trylock only where necessary X-Git-Tag: OPENLDAP_AC_BP~87 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=fa27310d774412d8a39739ae32e71f2da6cf1fcd;p=openldap use trylock only where necessary --- diff --git a/servers/slapd/back-ldap/bind.c b/servers/slapd/back-ldap/bind.c index f10b5feef9..d9e395d3ed 100644 --- a/servers/slapd/back-ldap/bind.c +++ b/servers/slapd/back-ldap/bind.c @@ -235,16 +235,7 @@ ldap_back_freeconn( Operation *op, struct ldapconn *lc ) { struct ldapinfo *li = (struct ldapinfo *) op->o_bd->be_private; -retry_lock:; - switch ( ldap_pvt_thread_mutex_trylock( &li->conn_mutex ) ) { - case LDAP_PVT_THREAD_EBUSY: - default: - ldap_pvt_thread_yield(); - goto retry_lock; - - case 0: - break; - } + ldap_pvt_thread_mutex_lock( &li->conn_mutex ); assert( lc->lc_refcnt > 0 ); if ( --lc->lc_refcnt == 0 ) { @@ -430,16 +421,7 @@ ldap_back_getconn( Operation *op, SlapReply *rs, ldap_back_send_t sendok ) lc_curr.lc_local_ndn = op->o_ndn; } -retry_lock:; - switch ( ldap_pvt_thread_mutex_trylock( &li->conn_mutex ) ) { - case LDAP_PVT_THREAD_EBUSY: - default: - ldap_pvt_thread_yield(); - goto retry_lock; - - case 0: - break; - } + ldap_pvt_thread_mutex_lock( &li->conn_mutex ); lc = (struct ldapconn *)avl_find( li->conntree, (caddr_t)&lc_curr, ldap_back_conn_cmp ); @@ -475,16 +457,7 @@ retry_lock:; lc->lc_bound = 0; /* Inserts the newly created ldapconn in the avl tree */ -retry_lock2:; - switch ( ldap_pvt_thread_mutex_trylock( &li->conn_mutex ) ) { - case LDAP_PVT_THREAD_EBUSY: - default: - ldap_pvt_thread_yield(); - goto retry_lock2; - - case 0: - break; - } + ldap_pvt_thread_mutex_lock( &li->conn_mutex ); assert( lc->lc_refcnt == 1 ); rs->sr_err = avl_insert( &li->conntree, (caddr_t)lc, @@ -528,17 +501,7 @@ ldap_back_release_conn( { struct ldapinfo *li = (struct ldapinfo *)op->o_bd->be_private; -retry_lock:; - switch ( ldap_pvt_thread_mutex_trylock( &li->conn_mutex ) ) { - case LDAP_PVT_THREAD_EBUSY: - default: - ldap_pvt_thread_yield(); - goto retry_lock; - - case 0: - break; - } - + ldap_pvt_thread_mutex_lock( &li->conn_mutex ); assert( lc->lc_refcnt > 0 ); lc->lc_refcnt--; ldap_pvt_thread_mutex_unlock( &li->conn_mutex ); @@ -655,16 +618,7 @@ retry:; if ( rs->sr_err == LDAP_SERVER_DOWN ) { if ( retries > 0 ) { if ( dolock ) { -retry_lock:; - switch ( ldap_pvt_thread_mutex_trylock( &li->conn_mutex ) ) { - case LDAP_PVT_THREAD_EBUSY: - default: - ldap_pvt_thread_yield(); - goto retry_lock; - - case 0: - break; - } + ldap_pvt_thread_mutex_lock( &li->conn_mutex ); } assert( lc->lc_refcnt > 0 ); @@ -820,16 +774,7 @@ ldap_back_retry( struct ldapconn *lc, Operation *op, SlapReply *rs, ldap_back_se int rc = 0; struct ldapinfo *li = (struct ldapinfo *)op->o_bd->be_private; -retry_lock:; - switch ( ldap_pvt_thread_mutex_trylock( &li->conn_mutex ) ) { - case LDAP_PVT_THREAD_EBUSY: - default: - ldap_pvt_thread_yield(); - goto retry_lock; - - case 0: - break; - } + ldap_pvt_thread_mutex_lock( &li->conn_mutex ); if ( lc->lc_refcnt == 1 ) { ldap_unbind_ext( lc->lc_ld, NULL, NULL ); diff --git a/servers/slapd/back-ldap/unbind.c b/servers/slapd/back-ldap/unbind.c index aa699342b6..180441a44d 100644 --- a/servers/slapd/back-ldap/unbind.c +++ b/servers/slapd/back-ldap/unbind.c @@ -48,17 +48,7 @@ ldap_back_conn_destroy( lc_curr.lc_conn = conn; lc_curr.lc_local_ndn = conn->c_ndn; -retry_lock:; - switch ( ldap_pvt_thread_mutex_trylock( &li->conn_mutex ) ) { - case LDAP_PVT_THREAD_EBUSY: - default: - ldap_pvt_thread_yield(); - goto retry_lock; - - case 0: - break; - } - + ldap_pvt_thread_mutex_trylock( &li->conn_mutex ); lc = avl_delete( &li->conntree, (caddr_t)&lc_curr, ldap_back_conn_cmp ); ldap_pvt_thread_mutex_unlock( &li->conn_mutex ); diff --git a/servers/slapd/back-meta/bind.c b/servers/slapd/back-meta/bind.c index a1605805bc..f7bc68ff87 100644 --- a/servers/slapd/back-meta/bind.c +++ b/servers/slapd/back-meta/bind.c @@ -265,17 +265,7 @@ retry:; rc = slap_map_api2result( rs ); if ( rs->sr_err == LDAP_UNAVAILABLE && nretries != META_RETRY_NEVER ) { -retry_lock:; - switch ( ldap_pvt_thread_mutex_trylock( &mi->mi_conn_mutex ) ) { - case LDAP_PVT_THREAD_EBUSY: - default: - ldap_pvt_thread_yield(); - goto retry_lock; - - case 0: - break; - } - + ldap_pvt_thread_mutex_lock( &mi->mi_conn_mutex ); if ( mc->mc_refcnt == 1 ) { ldap_unbind_ext_s( msc->msc_ld, NULL, NULL ); msc->msc_ld = NULL; @@ -444,16 +434,7 @@ retry:; rc = slap_map_api2result( rs ); if ( rc == LDAP_UNAVAILABLE && nretries != META_RETRY_NEVER ) { if ( dolock ) { -retry_lock:; - switch ( ldap_pvt_thread_mutex_trylock( &mi->mi_conn_mutex ) ) { - case LDAP_PVT_THREAD_EBUSY: - default: - ldap_pvt_thread_yield(); - goto retry_lock; - - case 0: - break; - } + ldap_pvt_thread_mutex_lock( &mi->mi_conn_mutex ); } if ( mc->mc_refcnt == 1 ) { diff --git a/servers/slapd/back-meta/conn.c b/servers/slapd/back-meta/conn.c index f1f80d72e3..422107d78d 100644 --- a/servers/slapd/back-meta/conn.c +++ b/servers/slapd/back-meta/conn.c @@ -178,16 +178,7 @@ meta_back_freeconn( assert( mc != NULL ); -retry_lock:; - switch ( ldap_pvt_thread_mutex_trylock( &mi->mi_conn_mutex ) ) { - case LDAP_PVT_THREAD_EBUSY: - default: - ldap_pvt_thread_yield(); - goto retry_lock; - - case 0: - break; - } + ldap_pvt_thread_mutex_lock( &mi->mi_conn_mutex ); if ( --mc->mc_refcnt == 0 ) { meta_back_conn_free( mc ); @@ -412,20 +403,16 @@ meta_back_retry( metasingleconn_t *msc = &mc->mc_conns[ candidate ]; retry_lock:; - switch ( ldap_pvt_thread_mutex_trylock( &mi->mi_conn_mutex ) ) { - case LDAP_PVT_THREAD_EBUSY: - default: - ldap_pvt_thread_yield(); - goto retry_lock; - - case 0: - break; - } + ldap_pvt_thread_mutex_lock( &mi->mi_conn_mutex ); assert( mc->mc_refcnt > 0 ); if ( mc->mc_refcnt == 1 ) { - ldap_pvt_thread_mutex_lock( &mc->mc_mutex ); + while ( ldap_pvt_thread_mutex_trylock( &mc->mc_mutex ) ) { + ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex ); + ldap_pvt_thread_yield(); + goto retry_lock; + } ldap_unbind_ext_s( msc->msc_ld, NULL, NULL ); msc->msc_ld = NULL; @@ -671,16 +658,7 @@ meta_back_getconn( /* Searches for a metaconn in the avl tree */ mc_curr.mc_conn = op->o_conn; -retry_lock:; - switch ( ldap_pvt_thread_mutex_trylock( &mi->mi_conn_mutex ) ) { - case LDAP_PVT_THREAD_EBUSY: - default: - ldap_pvt_thread_yield(); - goto retry_lock; - - case 0: - break; - } + ldap_pvt_thread_mutex_lock( &mi->mi_conn_mutex ); mc = (metaconn_t *)avl_find( mi->mi_conntree, (caddr_t)&mc_curr, meta_back_conn_cmp ); if ( mc ) { @@ -849,16 +827,7 @@ retry_lock:; * the reason is that the connection might have been * created by meta_back_get_candidate() */ mc_curr.mc_conn = op->o_conn; -retry_lock2:; - switch ( ldap_pvt_thread_mutex_trylock( &mi->mi_conn_mutex ) ) { - case LDAP_PVT_THREAD_EBUSY: - default: - ldap_pvt_thread_yield(); - goto retry_lock2; - - case 0: - break; - } + ldap_pvt_thread_mutex_lock( &mi->mi_conn_mutex ); mc = (metaconn_t *)avl_find( mi->mi_conntree, (caddr_t)&mc_curr, meta_back_conn_cmp ); if ( mc != NULL ) { @@ -1003,16 +972,7 @@ done:; /* * Inserts the newly created metaconn in the avl tree */ -retry_lock3:; - switch ( ldap_pvt_thread_mutex_trylock( &mi->mi_conn_mutex ) ) { - case LDAP_PVT_THREAD_EBUSY: - default: - ldap_pvt_thread_yield(); - goto retry_lock3; - - case 0: - break; - } + ldap_pvt_thread_mutex_lock( &mi->mi_conn_mutex ); err = avl_insert( &mi->mi_conntree, ( caddr_t )mc, meta_back_conn_cmp, meta_back_conn_dup ); @@ -1065,17 +1025,7 @@ meta_back_release_conn( assert( mc != NULL ); -retry_lock:; - switch ( ldap_pvt_thread_mutex_trylock( &mi->mi_conn_mutex ) ) { - case LDAP_PVT_THREAD_EBUSY: - default: - ldap_pvt_thread_yield(); - goto retry_lock; - - case 0: - break; - } - + ldap_pvt_thread_mutex_lock( &mi->mi_conn_mutex ); assert( mc->mc_refcnt > 0 ); mc->mc_refcnt--; ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex ); diff --git a/servers/slapd/back-meta/unbind.c b/servers/slapd/back-meta/unbind.c index e3d8a60421..93a694b02b 100644 --- a/servers/slapd/back-meta/unbind.c +++ b/servers/slapd/back-meta/unbind.c @@ -49,17 +49,7 @@ meta_back_conn_destroy( mc_curr.mc_conn = conn; -retry_lock:; - switch ( ldap_pvt_thread_mutex_trylock( &mi->mi_conn_mutex ) ) { - case LDAP_PVT_THREAD_EBUSY: - default: - ldap_pvt_thread_yield(); - goto retry_lock; - - case 0: - break; - } - + ldap_pvt_thread_mutex_lock( &mi->mi_conn_mutex ); mc = avl_delete( &mi->mi_conntree, ( caddr_t )&mc_curr, meta_back_conn_cmp ); ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex );