X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fback-ldbm%2Fdbcache.c;h=5e3549ff34f0ca0e8b722f1caa582d5bb6978cde;hb=ab620c46541dd9b8306008a170cc5a5be0f12eb2;hp=c16c8b160dfdfe210188465c5e9f19fe74636ad4;hpb=42e0d83cb3a1a1c5b25183f1ab74ce7edbe25de7;p=openldap diff --git a/servers/slapd/back-ldbm/dbcache.c b/servers/slapd/back-ldbm/dbcache.c index c16c8b160d..5e3549ff34 100644 --- a/servers/slapd/back-ldbm/dbcache.c +++ b/servers/slapd/back-ldbm/dbcache.c @@ -1,24 +1,23 @@ /* ldbmcache.c - maintain a cache of open ldbm files */ +#include "portable.h" + #include -#include -#include -#include -#include -#include + +#include +#include +#include +#include + #include -#include -#include "portable.h" -#include "slap.h" -#include "ldapconfig.h" -#include "back-ldbm.h" -#ifndef SYSERRLIST_IN_STDIO -extern int sys_nerr; -extern char *sys_errlist[]; +#ifdef HAVE_SYS_PARAM_H +#include #endif -extern time_t currenttime; -extern pthread_mutex_t currenttime_mutex; + +#include "ldapconfig.h" +#include "slap.h" +#include "back-ldbm.h" struct dbcache * ldbm_cache_open( @@ -41,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 */ @@ -54,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] ); } @@ -75,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 @@ -98,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 ) { @@ -110,16 +109,16 @@ 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; Debug( LDAP_DEBUG_ARGS, - "ldbm_cache_open (blksize %d) (maxids %d) (maxindirect %d)\n", + "ldbm_cache_open (blksize %ld) (maxids %d) (maxindirect %d)\n", 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] ); } @@ -128,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 @@ -140,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 @@ -156,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 @@ -177,24 +174,10 @@ ldbm_cache_fetch( { Datum data; - 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 ); } @@ -208,17 +191,25 @@ 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", + key.dptr, key.dsize, 0, 0, 0 ); - rc = ldbm_store( db->dbc_db, key, data, flags ); + Statslog( LDAP_DEBUG_STATS, + "=> ldbm_cache_store(): key.dptr=0x%08x, data.dptr=0x%0 8x\n", + key.dptr, data.dptr, 0, 0, 0 ); - pthread_mutex_unlock( &db->dbc_mutex ); + Statslog( LDAP_DEBUG_STATS, + "=> ldbm_cache_store(): data.dptr=%s, data.dsize=%d\n", + data.dptr, data.dsize, 0, 0, 0 ); + + Statslog( LDAP_DEBUG_STATS, + "=> ldbm_cache_store(): flags=0x%08x\n", + flags, 0, 0, 0, 0 ); +#endif /* LDBM_DEBUG */ + + rc = ldbm_store( db->dbc_db, key, data, flags ); return( rc ); } @@ -231,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 ); }