Hide allocate of reentrant_database cond varible and reader count

behind REENTRANT_DATABASE.  rename reentrant_database -> REENTRANT_DATABASE.
When REENTRANT_DATABASE is defined, the simple lock is replaced
with a simple reader/writer lock.  This functionality should be removed
from back-ldbm to libldbm.
This commit is contained in:
Kurt Zeilenga 1999-01-26 17:23:50 +00:00
parent 3c67248a65
commit f1e934effb
3 changed files with 8 additions and 4 deletions

View file

@ -75,8 +75,10 @@ struct dbcache {
int dbc_refcnt;
time_t dbc_lastref;
pthread_mutex_t dbc_mutex;
#ifdef REENTRANT_DATBASE
pthread_cond_t dbc_cv;
int dbc_readers;
#endif
long dbc_blksize;
int dbc_maxids;
int dbc_maxindirect;

View file

@ -179,7 +179,7 @@ ldbm_cache_fetch(
ldbm_datum_init( data );
pthread_mutex_lock( &db->dbc_mutex );
#ifdef reentrant_database
#ifdef REENTRANT_DATABASE
/* increment reader count */
db->dbc_readers++
pthread_mutex_unlock( &db->dbc_mutex );
@ -187,7 +187,7 @@ ldbm_cache_fetch(
data = ldbm_fetch( db->dbc_db, key );
#ifdef reentrant_database
#ifdef REENTRANT_DATABASE
pthread_mutex_lock( &db->dbc_mutex );
/* decrement reader count & signal any waiting writers */
if ( --db->dbc_readers == 0 ) {
@ -210,7 +210,7 @@ ldbm_cache_store(
int rc;
pthread_mutex_lock( &db->dbc_mutex );
#ifdef reentrant_database
#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 );
@ -251,7 +251,7 @@ ldbm_cache_delete(
int rc;
pthread_mutex_lock( &db->dbc_mutex );
#ifdef reentrant_database
#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 );

View file

@ -80,8 +80,10 @@ ldbm_back_init(
for ( i = 0; i < MAXDBCACHE; i++ ) {
pthread_mutex_init( &li->li_dbcache[i].dbc_mutex,
pthread_mutexattr_default );
#ifdef reentrant_database
pthread_cond_init( &li->li_dbcache[i].dbc_cv,
pthread_condattr_default );
#endif
}
#ifdef HAVE_BERKELEY_DB2
pthread_mutex_init( &dbEnvInit_mutex, pthread_mutexattr_default );