X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fback-ldbm%2Fdbcache.c;h=5e3549ff34f0ca0e8b722f1caa582d5bb6978cde;hb=ab620c46541dd9b8306008a170cc5a5be0f12eb2;hp=3da34b0126ffc18cd9793b8b8651e1e5dc335a13;hpb=3952bc8e95a2b21aced14f890028f12d00e191fa;p=openldap diff --git a/servers/slapd/back-ldbm/dbcache.c b/servers/slapd/back-ldbm/dbcache.c index 3da34b0126..5e3549ff34 100644 --- a/servers/slapd/back-ldbm/dbcache.c +++ b/servers/slapd/back-ldbm/dbcache.c @@ -40,12 +40,12 @@ ldbm_cache_open( flags, li->li_mode ); lru = 0; - pthread_mutex_lock( ¤ttime_mutex ); + ldap_pvt_thread_mutex_lock( ¤ttime_mutex ); curtime = currenttime; - pthread_mutex_unlock( ¤ttime_mutex ); + ldap_pvt_thread_mutex_unlock( ¤ttime_mutex ); oldtime = curtime; - pthread_mutex_lock( &li->li_dbcache_mutex ); + ldap_pvt_thread_mutex_lock( &li->li_dbcache_mutex ); for ( i = 0; i < MAXDBCACHE && li->li_dbcache[i].dbc_name != NULL; i++ ) { /* already open - return it */ @@ -53,7 +53,7 @@ ldbm_cache_open( li->li_dbcache[i].dbc_refcnt++; Debug( LDAP_DEBUG_TRACE, "<= ldbm_cache_open (cache %d)\n", i, 0, 0 ); - pthread_mutex_unlock( &li->li_dbcache_mutex ); + ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex ); return( &li->li_dbcache[i] ); } @@ -74,7 +74,7 @@ ldbm_cache_open( 0, 0, 0 ); lru = -1; while ( lru == -1 ) { - pthread_cond_wait( &li->li_dbcache_cv, + ldap_pvt_thread_cond_wait( &li->li_dbcache_cv, &li->li_dbcache_mutex ); for ( i = 0; i < MAXDBCACHE; i++ ) { if ( li->li_dbcache[i].dbc_refcnt @@ -97,10 +97,10 @@ ldbm_cache_open( "<= ldbm_cache_open NULL \"%s\" errno %d reason \"%s\")\n", buf, errno, errno > -1 && errno < sys_nerr ? sys_errlist[errno] : "unknown" ); - pthread_mutex_unlock( &li->li_dbcache_mutex ); + ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex ); return( NULL ); } - li->li_dbcache[i].dbc_name = strdup( buf ); + li->li_dbcache[i].dbc_name = ch_strdup( buf ); li->li_dbcache[i].dbc_refcnt = 1; li->li_dbcache[i].dbc_lastref = curtime; if ( stat( buf, &st ) == 0 ) { @@ -109,7 +109,7 @@ ldbm_cache_open( li->li_dbcache[i].dbc_blksize = DEFAULT_BLOCKSIZE; } li->li_dbcache[i].dbc_maxids = (li->li_dbcache[i].dbc_blksize / - sizeof(ID)) - 2; + sizeof(ID)) - ID_BLOCK_IDS_OFFSET; li->li_dbcache[i].dbc_maxindirect = (SLAPD_LDBM_MIN_MAXIDS / li->li_dbcache[i].dbc_maxids) + 1; @@ -118,7 +118,7 @@ ldbm_cache_open( li->li_dbcache[i].dbc_blksize, li->li_dbcache[i].dbc_maxids, li->li_dbcache[i].dbc_maxindirect ); Debug( LDAP_DEBUG_TRACE, "<= ldbm_cache_open (opened %d)\n", i, 0, 0 ); - pthread_mutex_unlock( &li->li_dbcache_mutex ); + ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex ); return( &li->li_dbcache[i] ); } @@ -127,11 +127,11 @@ ldbm_cache_close( Backend *be, struct dbcache *db ) { struct ldbminfo *li = (struct ldbminfo *) be->be_private; - pthread_mutex_lock( &li->li_dbcache_mutex ); + ldap_pvt_thread_mutex_lock( &li->li_dbcache_mutex ); if ( --db->dbc_refcnt == 0 ) { - pthread_cond_signal( &li->li_dbcache_cv ); + ldap_pvt_thread_cond_signal( &li->li_dbcache_cv ); } - pthread_mutex_unlock( &li->li_dbcache_mutex ); + ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex ); } void @@ -139,14 +139,14 @@ ldbm_cache_really_close( Backend *be, struct dbcache *db ) { struct ldbminfo *li = (struct ldbminfo *) be->be_private; - pthread_mutex_lock( &li->li_dbcache_mutex ); + ldap_pvt_thread_mutex_lock( &li->li_dbcache_mutex ); if ( --db->dbc_refcnt == 0 ) { - pthread_cond_signal( &li->li_dbcache_cv ); + ldap_pvt_thread_cond_signal( &li->li_dbcache_cv ); ldbm_close( db->dbc_db ); free( db->dbc_name ); db->dbc_name = NULL; } - pthread_mutex_unlock( &li->li_dbcache_mutex ); + ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex ); } void @@ -155,17 +155,15 @@ ldbm_cache_flush_all( Backend *be ) struct ldbminfo *li = (struct ldbminfo *) be->be_private; int i; - pthread_mutex_lock( &li->li_dbcache_mutex ); + ldap_pvt_thread_mutex_lock( &li->li_dbcache_mutex ); for ( i = 0; i < MAXDBCACHE; i++ ) { if ( li->li_dbcache[i].dbc_name != NULL ) { Debug( LDAP_DEBUG_TRACE, "ldbm flushing db (%s)\n", li->li_dbcache[i].dbc_name, 0, 0 ); - pthread_mutex_lock( &li->li_dbcache[i].dbc_mutex ); ldbm_sync( li->li_dbcache[i].dbc_db ); - pthread_mutex_unlock( &li->li_dbcache[i].dbc_mutex ); } } - pthread_mutex_unlock( &li->li_dbcache_mutex ); + ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex ); } Datum @@ -175,28 +173,11 @@ ldbm_cache_fetch( ) { Datum data; -#ifdef HAVE_BERKELEY_DB2 - memset( &data, 0, sizeof( data ) ); -#endif - pthread_mutex_lock( &db->dbc_mutex ); -#ifdef reentrant_database - /* increment reader count */ - db->dbc_readers++ - pthread_mutex_unlock( &db->dbc_mutex ); -#endif + ldbm_datum_init( data ); data = ldbm_fetch( db->dbc_db, key ); -#ifdef reentrant_database - pthread_mutex_lock( &db->dbc_mutex ); - /* decrement reader count & signal any waiting writers */ - if ( --db->dbc_readers == 0 ) { - pthread_cond_signal( &db->dbc_cv ); - } -#endif - pthread_mutex_unlock( &db->dbc_mutex ); - return( data ); } @@ -210,14 +191,6 @@ ldbm_cache_store( { int rc; - pthread_mutex_lock( &db->dbc_mutex ); -#ifdef reentrant_database - /* wait for reader count to drop to zero */ - while ( db->dbc_readers > 0 ) { - pthread_cond_wait( &db->dbc_cv, &db->dbc_mutex ); - } -#endif - #ifdef LDBM_DEBUG Statslog( LDAP_DEBUG_STATS, "=> ldbm_cache_store(): key.dptr=%s, key.dsize=%d\n", @@ -238,8 +211,6 @@ ldbm_cache_store( rc = ldbm_store( db->dbc_db, key, data, flags ); - pthread_mutex_unlock( &db->dbc_mutex ); - return( rc ); } @@ -251,17 +222,7 @@ ldbm_cache_delete( { int rc; - pthread_mutex_lock( &db->dbc_mutex ); -#ifdef reentrant_database - /* wait for reader count to drop to zero - then write */ - while ( db->dbc_readers > 0 ) { - pthread_cond_wait( &db->dbc_cv, &db->dbc_mutex ); - } -#endif - rc = ldbm_delete( db->dbc_db, key ); - pthread_mutex_unlock( &db->dbc_mutex ); - return( rc ); }