mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-02-11 13:50:39 +08:00
Deleted bi_database_mutex, use DB_LOCK instead. Changed bdb_locker_id to
lookup the threadctx if no Op * is provided. (bdb_db_cache doesn't know its thread context when it acquires a locker ID.)
This commit is contained in:
parent
d68391c37f
commit
0be6cb5a67
@ -110,7 +110,6 @@ struct bdb_info {
|
||||
|
||||
int bi_ndatabases;
|
||||
struct bdb_db_info **bi_databases;
|
||||
ldap_pvt_thread_mutex_t bi_database_mutex;
|
||||
int bi_db_opflags; /* db-specific flags */
|
||||
|
||||
slap_mask_t bi_defaultmask;
|
||||
|
@ -1143,16 +1143,24 @@ bdb_locker_id( Operation *op, DB_ENV *env, int *locker )
|
||||
{
|
||||
int i, rc, lockid;
|
||||
void *data;
|
||||
void *ctx;
|
||||
|
||||
if ( !env || !op || !locker ) return -1;
|
||||
if ( !env || !locker ) return -1;
|
||||
|
||||
/* If no op was provided, try to find the ctx anyway... */
|
||||
if ( op ) {
|
||||
ctx = op->o_threadctx;
|
||||
} else {
|
||||
ctx = ldap_pvt_thread_pool_context( &connection_pool );
|
||||
}
|
||||
|
||||
/* Shouldn't happen unless we're single-threaded */
|
||||
if ( !op->o_threadctx ) {
|
||||
if ( !ctx ) {
|
||||
*locker = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( ldap_pvt_thread_pool_getkey( op->o_threadctx, env, &data, NULL ) ) {
|
||||
if ( ldap_pvt_thread_pool_getkey( ctx, env, &data, NULL ) ) {
|
||||
for ( i=0, rc=1; rc != 0 && i<4; i++ ) {
|
||||
rc = XLOCK_ID( env, &lockid );
|
||||
if (rc) ldap_pvt_thread_yield();
|
||||
@ -1161,7 +1169,7 @@ bdb_locker_id( Operation *op, DB_ENV *env, int *locker )
|
||||
return rc;
|
||||
}
|
||||
data = (void *)lockid;
|
||||
if ( ( rc = ldap_pvt_thread_pool_setkey( op->o_threadctx, env,
|
||||
if ( ( rc = ldap_pvt_thread_pool_setkey( ctx, env,
|
||||
data, bdb_locker_id_free ) ) ) {
|
||||
XLOCK_ID_FREE( env, lockid );
|
||||
#ifdef NEW_LOGGING
|
||||
|
@ -56,6 +56,9 @@ bdb_db_cache(
|
||||
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
|
||||
struct bdb_db_info *db;
|
||||
char *file;
|
||||
DBT lockobj;
|
||||
DB_LOCK lock;
|
||||
u_int32_t locker = 0;
|
||||
|
||||
*dbout = NULL;
|
||||
|
||||
@ -66,19 +69,33 @@ bdb_db_cache(
|
||||
}
|
||||
}
|
||||
|
||||
ldap_pvt_thread_mutex_lock( &bdb->bi_database_mutex );
|
||||
lockobj.data = "bdb_db_cache";
|
||||
lockobj.size = sizeof("bdb_db_cache");
|
||||
|
||||
if (tid) {
|
||||
locker = TXN_ID( tid );
|
||||
} else {
|
||||
#ifdef BDB_REUSE_LOCKERS
|
||||
#define op NULL /* implicit arg in LOCK_ID */
|
||||
#endif
|
||||
rc = LOCK_ID( bdb->bi_dbenv, &locker );
|
||||
if (rc) return rc;
|
||||
}
|
||||
rc = LOCK_GET( bdb->bi_dbenv, locker, 0, &lockobj,
|
||||
DB_LOCK_WRITE, &lock );
|
||||
if (rc) return rc;
|
||||
|
||||
/* check again! may have been added by another thread */
|
||||
for( i=BDB_NDB; bdb->bi_databases[i]; i++ ) {
|
||||
if( !strcmp( bdb->bi_databases[i]->bdi_name, name) ) {
|
||||
*dbout = bdb->bi_databases[i]->bdi_db;
|
||||
ldap_pvt_thread_mutex_unlock( &bdb->bi_database_mutex );
|
||||
LOCK_PUT( bdb->bi_dbenv, &lock);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if( i >= BDB_INDICES ) {
|
||||
ldap_pvt_thread_mutex_unlock( &bdb->bi_database_mutex );
|
||||
LOCK_PUT( bdb->bi_dbenv, &lock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -97,7 +114,7 @@ bdb_db_cache(
|
||||
"bdb_db_cache: db_create(%s) failed: %s (%d)\n",
|
||||
bdb->bi_dbenv_home, db_strerror(rc), rc );
|
||||
#endif
|
||||
ldap_pvt_thread_mutex_unlock( &bdb->bi_database_mutex );
|
||||
LOCK_PUT( bdb->bi_dbenv, &lock);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -131,7 +148,7 @@ bdb_db_cache(
|
||||
"bdb_db_cache: db_open(%s) failed: %s (%d)\n",
|
||||
name, db_strerror(rc), rc );
|
||||
#endif
|
||||
ldap_pvt_thread_mutex_unlock( &bdb->bi_database_mutex );
|
||||
LOCK_PUT( bdb->bi_dbenv, &lock);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -141,6 +158,6 @@ bdb_db_cache(
|
||||
|
||||
*dbout = db->bdi_db;
|
||||
|
||||
ldap_pvt_thread_mutex_unlock( &bdb->bi_database_mutex );
|
||||
LOCK_PUT( bdb->bi_dbenv, &lock );
|
||||
return 0;
|
||||
}
|
||||
|
@ -98,7 +98,6 @@ bdb_db_init( BackendDB *be )
|
||||
LDAP_LIST_INIT (&bdb->psearch_list);
|
||||
#endif
|
||||
|
||||
ldap_pvt_thread_mutex_init( &bdb->bi_database_mutex );
|
||||
ldap_pvt_thread_mutex_init( &bdb->bi_lastid_mutex );
|
||||
ldap_pvt_thread_mutex_init( &bdb->bi_cache.lru_mutex );
|
||||
ldap_pvt_thread_rdwr_init ( &bdb->bi_cache.c_rwlock );
|
||||
@ -525,7 +524,6 @@ bdb_db_destroy( BackendDB *be )
|
||||
ldap_pvt_thread_rdwr_destroy ( &bdb->bi_cache.c_rwlock );
|
||||
ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.lru_mutex );
|
||||
ldap_pvt_thread_mutex_destroy( &bdb->bi_lastid_mutex );
|
||||
ldap_pvt_thread_mutex_destroy( &bdb->bi_database_mutex );
|
||||
|
||||
ch_free( bdb );
|
||||
be->be_private = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user