mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-01-24 13:24:56 +08:00
IDL cache locking change (mutex -> rwlock)
This commit is contained in:
parent
a69d32153f
commit
420210a2a3
@ -145,7 +145,8 @@ struct bdb_info {
|
||||
Avlnode *bi_idl_tree;
|
||||
bdb_idl_cache_entry_t *bi_idl_lru_head;
|
||||
bdb_idl_cache_entry_t *bi_idl_lru_tail;
|
||||
ldap_pvt_thread_mutex_t bi_idl_tree_mutex;
|
||||
ldap_pvt_thread_rdwr_t bi_idl_tree_rwlock;
|
||||
ldap_pvt_thread_mutex_t bi_idl_tree_lrulock;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -352,17 +352,19 @@ bdb_idl_fetch_key(
|
||||
bdb_idl_cache_entry_t *matched_idl_entry;
|
||||
DBT2bv( key, &idl_tmp.kstr );
|
||||
idl_tmp.db = db;
|
||||
ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_mutex );
|
||||
ldap_pvt_thread_rdwr_rlock( &bdb->bi_idl_tree_rwlock );
|
||||
matched_idl_entry = avl_find( bdb->bi_idl_tree, &idl_tmp,
|
||||
bdb_idl_entry_cmp );
|
||||
if ( matched_idl_entry != NULL ) {
|
||||
BDB_IDL_CPY( ids, matched_idl_entry->idl );
|
||||
ldap_pvt_thread_rdwr_runlock( &bdb->bi_idl_tree_rwlock );
|
||||
ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_lrulock );
|
||||
IDL_LRU_DELETE( bdb, matched_idl_entry );
|
||||
IDL_LRU_ADD( bdb, matched_idl_entry );
|
||||
ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_mutex );
|
||||
ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_lrulock );
|
||||
return LDAP_SUCCESS;
|
||||
}
|
||||
ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_mutex );
|
||||
ldap_pvt_thread_rdwr_runlock( &bdb->bi_idl_tree_rwlock );
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -492,41 +494,45 @@ bdb_idl_fetch_key(
|
||||
ee->idl_lru_next = NULL;
|
||||
BDB_IDL_CPY( ee->idl, ids );
|
||||
ber_dupbv( &ee->kstr, &idl_tmp.kstr );
|
||||
ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_mutex );
|
||||
ldap_pvt_thread_rdwr_wlock( &bdb->bi_idl_tree_rwlock );
|
||||
if ( avl_insert( &bdb->bi_idl_tree, (caddr_t) ee,
|
||||
bdb_idl_entry_cmp, avl_dup_error ))
|
||||
{
|
||||
ch_free( ee->kstr.bv_val );
|
||||
ch_free( ee->idl );
|
||||
ch_free( ee );
|
||||
} else {
|
||||
IDL_LRU_ADD( bdb, ee );
|
||||
if ( ++bdb->bi_idl_cache_size > bdb->bi_idl_cache_max_size ) {
|
||||
int i = 0;
|
||||
while ( bdb->bi_idl_lru_tail != NULL && i < 10 ) {
|
||||
ee = bdb->bi_idl_lru_tail;
|
||||
if ( avl_delete( &bdb->bi_idl_tree, (caddr_t) ee,
|
||||
bdb_idl_entry_cmp ) == NULL ) {
|
||||
ldap_pvt_thread_rdwr_wunlock( &bdb->bi_idl_tree_rwlock );
|
||||
return rc;
|
||||
}
|
||||
ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_lrulock );
|
||||
IDL_LRU_ADD( bdb, ee );
|
||||
if ( ++bdb->bi_idl_cache_size > bdb->bi_idl_cache_max_size ) {
|
||||
int i = 0;
|
||||
while ( bdb->bi_idl_lru_tail != NULL && i < 10 ) {
|
||||
ee = bdb->bi_idl_lru_tail;
|
||||
if ( avl_delete( &bdb->bi_idl_tree, (caddr_t) ee,
|
||||
bdb_idl_entry_cmp ) == NULL ) {
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG( INDEX, ERR,
|
||||
"bdb_idl_fetch_key: AVL delete failed\n",
|
||||
0, 0, 0 );
|
||||
LDAP_LOG( INDEX, ERR,
|
||||
"bdb_idl_fetch_key: AVL delete failed\n",
|
||||
0, 0, 0 );
|
||||
#else
|
||||
Debug( LDAP_DEBUG_ANY, "=> bdb_idl_fetch_key: "
|
||||
"AVL delete failed\n",
|
||||
0, 0, 0 );
|
||||
Debug( LDAP_DEBUG_ANY, "=> bdb_idl_fetch_key: "
|
||||
"AVL delete failed\n",
|
||||
0, 0, 0 );
|
||||
#endif
|
||||
}
|
||||
IDL_LRU_DELETE( bdb, ee );
|
||||
i++;
|
||||
--bdb->bi_idl_cache_size;
|
||||
ch_free( ee->kstr.bv_val );
|
||||
ch_free( ee->idl );
|
||||
ch_free( ee );
|
||||
}
|
||||
IDL_LRU_DELETE( bdb, ee );
|
||||
i++;
|
||||
--bdb->bi_idl_cache_size;
|
||||
ch_free( ee->kstr.bv_val );
|
||||
ch_free( ee->idl );
|
||||
ch_free( ee );
|
||||
}
|
||||
}
|
||||
ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_mutex );
|
||||
|
||||
ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_lrulock );
|
||||
ldap_pvt_thread_rdwr_wunlock( &bdb->bi_idl_tree_rwlock );
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -569,7 +575,7 @@ bdb_idl_insert_key(
|
||||
bdb_idl_cache_entry_t *matched_idl_entry, idl_tmp;
|
||||
DBT2bv( key, &idl_tmp.kstr );
|
||||
idl_tmp.db = db;
|
||||
ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_mutex );
|
||||
ldap_pvt_thread_rdwr_wlock( &bdb->bi_idl_tree_rwlock );
|
||||
matched_idl_entry = avl_find( bdb->bi_idl_tree, &idl_tmp,
|
||||
bdb_idl_entry_cmp );
|
||||
if ( matched_idl_entry != NULL ) {
|
||||
@ -586,12 +592,14 @@ bdb_idl_insert_key(
|
||||
#endif
|
||||
}
|
||||
--bdb->bi_idl_cache_size;
|
||||
ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_lrulock );
|
||||
IDL_LRU_DELETE( bdb, matched_idl_entry );
|
||||
ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_lrulock );
|
||||
free( matched_idl_entry->kstr.bv_val );
|
||||
free( matched_idl_entry->idl );
|
||||
free( matched_idl_entry );
|
||||
}
|
||||
ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_mutex );
|
||||
ldap_pvt_thread_rdwr_wunlock( &bdb->bi_idl_tree_rwlock );
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -791,7 +799,7 @@ bdb_idl_delete_key(
|
||||
bdb_idl_cache_entry_t *matched_idl_entry, idl_tmp;
|
||||
DBT2bv( key, &idl_tmp.kstr );
|
||||
idl_tmp.db = db;
|
||||
ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_mutex );
|
||||
ldap_pvt_thread_rdwr_wlock( &bdb->bi_idl_tree_rwlock );
|
||||
matched_idl_entry = avl_find( bdb->bi_idl_tree, &idl_tmp,
|
||||
bdb_idl_entry_cmp );
|
||||
if ( matched_idl_entry != NULL ) {
|
||||
@ -808,12 +816,14 @@ bdb_idl_delete_key(
|
||||
#endif
|
||||
}
|
||||
--bdb->bi_idl_cache_size;
|
||||
ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_lrulock );
|
||||
IDL_LRU_DELETE( bdb, matched_idl_entry );
|
||||
ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_lrulock );
|
||||
free( matched_idl_entry->kstr.bv_val );
|
||||
free( matched_idl_entry->idl );
|
||||
free( matched_idl_entry );
|
||||
}
|
||||
ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_mutex );
|
||||
ldap_pvt_thread_rdwr_wunlock( &bdb->bi_idl_tree_rwlock );
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -200,7 +200,7 @@ bdb_db_open( BackendDB *be )
|
||||
|
||||
#ifdef SLAP_IDL_CACHE
|
||||
if ( bdb->bi_idl_cache_max_size ) {
|
||||
ldap_pvt_thread_mutex_init( &bdb->bi_idl_tree_mutex );
|
||||
ldap_pvt_thread_rdwr_init( &bdb->bi_idl_tree_rwlock );
|
||||
bdb->bi_idl_cache_size = 0;
|
||||
}
|
||||
#endif
|
||||
@ -460,7 +460,7 @@ bdb_db_close( BackendDB *be )
|
||||
bdb_cache_release_all (&bdb->bi_cache);
|
||||
|
||||
#ifdef SLAP_IDL_CACHE
|
||||
ldap_pvt_thread_mutex_lock ( &bdb->bi_idl_tree_mutex );
|
||||
ldap_pvt_thread_rdwr_wlock ( &bdb->bi_idl_tree_rwlock );
|
||||
entry = bdb->bi_idl_lru_head;
|
||||
while ( entry != NULL ) {
|
||||
next_entry = entry->idl_lru_next;
|
||||
@ -470,7 +470,7 @@ bdb_db_close( BackendDB *be )
|
||||
free( entry );
|
||||
entry = next_entry;
|
||||
}
|
||||
ldap_pvt_thread_mutex_unlock ( &bdb->bi_idl_tree_mutex );
|
||||
ldap_pvt_thread_rdwr_wunlock ( &bdb->bi_idl_tree_rwlock );
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user