]> git.sur5r.net Git - openldap/commitdiff
use trylock only where necessary
authorPierangelo Masarati <ando@openldap.org>
Sun, 7 Aug 2005 00:35:11 +0000 (00:35 +0000)
committerPierangelo Masarati <ando@openldap.org>
Sun, 7 Aug 2005 00:35:11 +0000 (00:35 +0000)
servers/slapd/back-ldap/bind.c
servers/slapd/back-ldap/unbind.c
servers/slapd/back-meta/bind.c
servers/slapd/back-meta/conn.c
servers/slapd/back-meta/unbind.c

index f10b5feef9807c36dcde016eeb4732d959102ffb..d9e395d3ed25f189a5101ab4dbcfe7e16abcd526 100644 (file)
@@ -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 );
index aa699342b6aa97f41f4dd4514d50bf38146d7316..180441a44d0d9ea22847227dd65c80131e03c363 100644 (file)
@@ -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 );
 
index a1605805bc373f95cac5e9d59a1cabedbccbd4d4..f7bc68ff87d094c882237c39bd563e16de60530e 100644 (file)
@@ -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 ) {
index f1f80d72e379d30bfe73ed59064fcfb4a2198ae5..422107d78d7cb82693b8fffc00e4e2dd6ebd30d9 100644 (file)
@@ -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 );
index e3d8a60421e3ea368d94fb9d974f812788e6e694..93a694b02bf9b6fa8ce73bbe7bfb243fc4dd10b0 100644 (file)
@@ -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 );