From: Pierangelo Masarati Date: Sat, 10 Jun 2006 15:30:24 +0000 (+0000) Subject: remove unnecessary locks and resource cleanup X-Git-Tag: OPENLDAP_REL_ENG_2_4_3ALPHA~9^2~153 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=6bd9aa3755264bdb4d90831b1701468d302a9cc6;p=openldap remove unnecessary locks and resource cleanup --- diff --git a/servers/slapd/back-meta/conn.c b/servers/slapd/back-meta/conn.c index 0f61ab2e21..3be9cacb40 100644 --- a/servers/slapd/back-meta/conn.c +++ b/servers/slapd/back-meta/conn.c @@ -223,24 +223,6 @@ metaconn_alloc( return mc; } -static void -meta_back_freeconn( - Operation *op, - metaconn_t *mc ) -{ - metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private; - - assert( mc != NULL ); - - ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex ); - - if ( --mc->mc_refcnt == 0 ) { - meta_back_conn_free( mc ); - } - - ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex ); -} - /* * meta_back_init_one_conn * @@ -996,7 +978,8 @@ retry_lock:; if ( ncandidates == 0 ) { if ( new_conn ) { - meta_back_freeconn( op, mc ); + mc->mc_refcnt = 0; + meta_back_conn_free( mc ); } else { meta_back_release_conn( op, mc ); @@ -1144,8 +1127,8 @@ retry_lock2:; */ META_CANDIDATE_RESET( &candidates[ i ] ); if ( new_conn ) { - (void)meta_clear_one_candidate( msc ); - meta_back_freeconn( op, mc ); + mc->mc_refcnt = 0; + meta_back_conn_free( mc ); } else { meta_back_release_conn( op, mc ); @@ -1230,7 +1213,8 @@ retry_lock2:; rs->sr_text = NULL; } if ( new_conn ) { - meta_back_freeconn( op, mc ); + mc->mc_refcnt = 0; + meta_back_conn_free( mc ); } else { meta_back_release_conn( op, mc ); @@ -1253,7 +1237,8 @@ retry_lock2:; if ( ncandidates == 0 ) { if ( new_conn ) { - meta_back_freeconn( op, mc ); + mc->mc_refcnt = 0; + meta_back_conn_free( mc ); } else { meta_back_release_conn( op, mc ); @@ -1324,8 +1309,9 @@ done:; "%s meta_back_getconn: candidates=%d conn=%ld insert failed\n", op->o_log_prefix, ncandidates, LDAP_BACK_PCONN_ID( mc->mc_conn ) ); - - meta_back_freeconn( op, mc ); + + mc->mc_refcnt = 0; + meta_back_conn_free( mc ); rs->sr_err = LDAP_OTHER; rs->sr_text = "proxy bind collision"; @@ -1368,12 +1354,11 @@ meta_back_release_conn_lock( mc->mc_refcnt--; LDAP_BACK_CONN_BINDING_CLEAR( mc ); if ( LDAP_BACK_CONN_TAINTED( mc ) ) { - Debug( LDAP_DEBUG_TRACE, "%s meta_back_release_conn: mc=%p conn=%ld expired.\n", + Debug( LDAP_DEBUG_TRACE, "%s meta_back_release_conn: mc=%p conn=%ld tainted.\n", op->o_log_prefix, (void *)mc, LDAP_BACK_PCONN_ID( mc->mc_conn ) ); (void)avl_delete( &mi->mi_conninfo.lai_tree, ( caddr_t )mc, meta_back_conndnmc_cmp ); if ( mc->mc_refcnt == 0 ) { - meta_clear_candidates( op, mc ); meta_back_conn_free( mc ); } } diff --git a/servers/slapd/back-meta/init.c b/servers/slapd/back-meta/init.c index df3b7dfc69..c06fbd277b 100644 --- a/servers/slapd/back-meta/init.c +++ b/servers/slapd/back-meta/init.c @@ -154,27 +154,33 @@ meta_back_db_open( return 0; } +/* + * meta_back_conn_free() + * + * actually frees a connection; the reference count must be 0, + * and it must not (or no longer) be in the cache. + */ void meta_back_conn_free( void *v_mc ) { metaconn_t *mc = v_mc; - int i, ntargets; + int ntargets; assert( mc != NULL ); assert( mc->mc_refcnt == 0 ); - if ( !BER_BVISNULL( &mc->mc_local_ndn ) ) { - free( mc->mc_local_ndn.bv_val ); - } - - assert( mc->mc_conns != NULL ); - /* at least one must be present... */ + assert( mc->mc_conns != NULL ); ntargets = mc->mc_conns[ 0 ].msc_info->mi_ntargets; + assert( ntargets > 0 ); + + for ( ; ntargets--; ) { + (void)meta_clear_one_candidate( &mc->mc_conns[ ntargets ] ); + } - for ( i = 0; i < ntargets; i++ ) { - (void)meta_clear_one_candidate( &mc->mc_conns[ i ] ); + if ( !BER_BVISNULL( &mc->mc_local_ndn ) ) { + free( mc->mc_local_ndn.bv_val ); } free( mc );