/*
* remaining fields require backend cache lock to access
- * These items are specific to the LDBM backend and should
+ * These items are specific to the BDB backend and should
* be hidden.
*/
int bei_state; /* for the cache */
static int bdb_cache_delete_entry_internal(Cache *cache, Entry *e);
#ifdef LDAP_DEBUG
-static void lru_print(Cache *cache);
+static void bdb_lru_print(Cache *cache);
#endif
static int
rw ? "w" : "r", e->e_id, 0);
#endif
-
if (rw)
return ldap_pvt_thread_rdwr_wtrylock(&BEI(e)->bei_rdwr);
else
rw ? "w" : "r", e->e_id, 0);
#endif
-
if (rw)
return ldap_pvt_thread_rdwr_wunlock(&BEI(e)->bei_rdwr);
else
ID id;
int refcnt, freeit = 1;
- /* set cache mutex */
- ldap_pvt_thread_mutex_lock( &cache->c_mutex );
+ /* set cache write lock */
+ ldap_pvt_thread_rdwr_wlock( &cache->c_rwlock );
assert( e->e_private );
* for instance)
*/
if ( BEI(e)->bei_state == CACHE_ENTRY_CREATING ) {
+ /* set lru mutex */
+ ldap_pvt_thread_mutex_lock( &cache->lru_mutex );
bdb_cache_delete_entry_internal( cache, e );
+ /* free lru mutex */
+ ldap_pvt_thread_mutex_unlock( &cache->lru_mutex );
freeit = 0;
/* now the entry is in DELETED state */
}
if ( BEI(e)->bei_state == CACHE_ENTRY_COMMITTED ) {
BEI(e)->bei_state = CACHE_ENTRY_READY;
- /* free cache mutex */
- ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+ /* free cache write lock */
+ ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock );
#ifdef NEW_LOGGING
LDAP_LOG(( "cache", LDAP_LEVEL_DETAIL1,
} else if ( BEI(e)->bei_state == CACHE_ENTRY_DELETED ) {
if( refcnt > 0 ) {
- /* free cache mutex */
- ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+ /* free cache write lock */
+ ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock );
#ifdef NEW_LOGGING
LDAP_LOG(( "cache", LDAP_LEVEL_DETAIL1,
rw ? "w" : "r", id, refcnt );
#endif
-
} else {
bdb_cache_entry_private_destroy( e );
if ( freeit ) {
bdb_entry_return( e );
}
- /* free cache mutex */
- ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+ /* free cache write lock */
+ ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock );
#ifdef NEW_LOGGING
LDAP_LOG(( "cache", LDAP_LEVEL_DETAIL1,
"====> bdb_cache_return_entry_%s( %ld ): deleted (%d)\n",
rw ? "w" : "r", id, refcnt );
#endif
-
}
} else {
- /* free cache mutex */
- ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+ /* free cache write lock */
+ ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock );
#ifdef NEW_LOGGING
LDAP_LOG(( "cache", LDAP_LEVEL_DETAIL1,
"====> bdb_cache_return_entry_%s( %ld ): returned (%d)\n",
rw ? "w" : "r", id, refcnt);
#endif
-
}
}
"bdb_cache_add_entry_rw: add (%s):%s to cache\n",
e->e_dn, rw ? "w" : "r" ));
#endif
- /* set cache mutex */
- ldap_pvt_thread_mutex_lock( &cache->c_mutex );
+ /* set cache write lock */
+ ldap_pvt_thread_rdwr_wlock( &cache->c_rwlock );
assert( e->e_private == NULL );
if( bdb_cache_entry_private_init(e) != 0 ) {
- /* free cache mutex */
- ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+ /* free cache write lock */
+ ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock );
#ifdef NEW_LOGGING
LDAP_LOG(( "cache", LDAP_LEVEL_ERR,
if ( avl_insert( &cache->c_dntree, (caddr_t) e,
(AVL_CMP) entry_dn_cmp, avl_dup_error ) != 0 )
{
- /* free cache mutex */
- ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+ /* free cache write lock */
+ ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock );
#ifdef NEW_LOGGING
LDAP_LOG(( "cache", LDAP_LEVEL_DETAIL1,
e->e_id, e->e_dn, 0 );
#endif
-
bdb_cache_entry_private_destroy(e);
return( 1 );
e->e_id, e->e_dn, 0 );
#endif
-
-
/* delete from dn tree inserted above */
if ( avl_delete( &cache->c_dntree, (caddr_t) e,
(AVL_CMP) entry_dn_cmp ) == NULL )
Debug( LDAP_DEBUG_ANY, "====> can't delete from dn cache\n",
0, 0, 0 );
#endif
-
}
bdb_cache_entry_private_destroy(e);
- /* free cache mutex */
- ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+ /* free cache write lock */
+ ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock );
return( -1 );
}
BEI(e)->bei_state = CACHE_ENTRY_CREATING;
BEI(e)->bei_refcnt = 1;
+ /* set lru mutex */
+ ldap_pvt_thread_mutex_lock( &cache->lru_mutex );
/* lru */
LRU_ADD( cache, e );
if ( ++cache->c_cursize > cache->c_maxsize ) {
}
}
- /* free cache mutex */
- ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+ /* free lru mutex */
+ ldap_pvt_thread_mutex_unlock( &cache->lru_mutex );
+ /* free cache write lock */
+ ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock );
return( 0 );
}
int i, rc;
Entry *ee;
- /* set cache mutex */
- ldap_pvt_thread_mutex_lock( &cache->c_mutex );
+ /* set cache write lock */
+ ldap_pvt_thread_rdwr_wlock( &cache->c_rwlock );
assert( e->e_private );
e->e_id, e->e_dn, 0 );
#endif
-
- /* free cache mutex */
- ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+ /* free cache write lock */
+ ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock );
return( 1 );
}
e->e_id, e->e_dn, 0 );
#endif
-
/* delete from dn tree inserted above */
if ( avl_delete( &cache->c_dntree, (caddr_t) e,
(AVL_CMP) entry_dn_cmp ) == NULL )
Debug( LDAP_DEBUG_ANY, "====> can't delete from dn cache\n",
0, 0, 0 );
#endif
-
}
- /* free cache mutex */
- ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+ /* free cache write lock */
+ ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock );
return( -1 );
}
/* will be marked after when entry is returned */
BEI(e)->bei_state = CACHE_ENTRY_CREATING;
+ /* set lru mutex */
+ ldap_pvt_thread_mutex_lock( &cache->lru_mutex );
/* lru */
LRU_ADD( cache, e );
if ( ++cache->c_cursize > cache->c_maxsize ) {
}
}
- /* free cache mutex */
- ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+ /* free lru mutex */
+ ldap_pvt_thread_mutex_unlock( &cache->lru_mutex );
+ /* free cache write lock */
+ ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock );
return( 0 );
}
e.e_nname = *ndn;
try_again:
- /* set cache mutex */
- ldap_pvt_thread_mutex_lock( &cache->c_mutex );
+ /* set cache read lock */
+ ldap_pvt_thread_rdwr_rlock( &cache->c_rwlock );
if ( (ep = (Entry *) avl_find( cache->c_dntree, (caddr_t) &e,
(AVL_CMP) entry_dn_cmp )) != NULL )
if ( state != CACHE_ENTRY_READY ) {
assert(state != CACHE_ENTRY_UNDEFINED);
- /* free cache mutex */
- ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+ /* free cache read lock */
+ ldap_pvt_thread_rdwr_runlock( &cache->c_rwlock );
#ifdef NEW_LOGGING
LDAP_LOG(( "cache", LDAP_LEVEL_INFO,
goto try_again;
}
+ /* free cache read lock */
+ ldap_pvt_thread_rdwr_runlock( &cache->c_rwlock );
+
+ /* set lru mutex */
+ ldap_pvt_thread_mutex_lock( &cache->lru_mutex );
+
/* lru */
LRU_DELETE( cache, ep );
LRU_ADD( cache, ep );
- /* free cache mutex */
- ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+ /* free lru mutex */
+ ldap_pvt_thread_mutex_unlock( &cache->lru_mutex );
#ifdef NEW_LOGGING
LDAP_LOG(( "cache", LDAP_LEVEL_DETAIL1,
ndn->bv_val, id, count);
#endif
-
} else {
- /* free cache mutex */
- ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+ /* free cache read lock */
+ ldap_pvt_thread_rdwr_runlock( &cache->c_rwlock );
id = NOID;
}
e.e_id = id;
try_again:
- /* set cache mutex */
- ldap_pvt_thread_mutex_lock( &cache->c_mutex );
+ /* set cache read lock */
+ ldap_pvt_thread_rdwr_rlock( &cache->c_rwlock );
if ( (ep = (Entry *) avl_find( cache->c_idtree, (caddr_t) &e,
(AVL_CMP) entry_id_cmp )) != NULL )
assert(state != CACHE_ENTRY_UNDEFINED);
- /* free cache mutex */
- ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+ /* free cache read lock */
+ ldap_pvt_thread_rdwr_runlock( &cache->c_rwlock );
#ifdef NEW_LOGGING
LDAP_LOG(( "cache", LDAP_LEVEL_INFO,
id, ep_id, state);
#endif
-
ldap_pvt_thread_yield();
goto try_again;
}
* so, unlock the cache, yield, and try again.
*/
- /* free cache mutex */
- ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+ /* free cache read lock */
+ ldap_pvt_thread_rdwr_runlock( &cache->c_rwlock );
#ifdef NEW_LOGGING
LDAP_LOG(( "cache", LDAP_LEVEL_INFO,
id, ep_id, state);
#endif
-
ldap_pvt_thread_yield();
goto try_again;
}
+ /* free cache read lock */
+ ldap_pvt_thread_rdwr_runlock( &cache->c_rwlock );
+ /* set lru mutex */
+ ldap_pvt_thread_mutex_lock( &cache->lru_mutex );
/* lru */
LRU_DELETE( cache, ep );
LRU_ADD( cache, ep );
BEI(ep)->bei_refcnt++;
- /* free cache mutex */
- ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+ /* free lru mutex */
+ ldap_pvt_thread_mutex_unlock( &cache->lru_mutex );
#ifdef NEW_LOGGING
LDAP_LOG(( "cache", LDAP_LEVEL_DETAIL1,
return( ep );
}
- /* free cache mutex */
- ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+ /* free cache read lock */
+ ldap_pvt_thread_rdwr_runlock( &cache->c_rwlock );
return( NULL );
}
{
int rc;
- /* set cache mutex */
- ldap_pvt_thread_mutex_lock( &cache->c_mutex );
+ /* set cache write lock */
+ ldap_pvt_thread_rdwr_wlock( &cache->c_rwlock );
assert( e->e_private );
e->e_id, 0, 0 );
#endif
-
+ /* set lru mutex */
+ ldap_pvt_thread_mutex_lock( &cache->lru_mutex );
rc = bdb_cache_delete_entry_internal( cache, e );
+ /* free lru mutex */
+ ldap_pvt_thread_mutex_unlock( &cache->lru_mutex );
- /* free cache mutex */
- ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+ /* free cache write lock */
+ ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock );
return( rc );
}
Entry *e;
int rc;
- /* set cache mutex */
- ldap_pvt_thread_mutex_lock( &cache->c_mutex );
+ /* set cache write lock */
+ ldap_pvt_thread_rdwr_wlock( &cache->c_rwlock );
+ /* set lru mutex */
+ ldap_pvt_thread_mutex_lock( &cache->lru_mutex );
#ifdef NEW_LOGGING
LDAP_LOG(( "cache", LDAP_LEVEL_ENTRY,
Debug( LDAP_DEBUG_TRACE, "====> bdb_cache_release_all\n", 0, 0, 0 );
#endif
-
while ( (e = cache->c_lrutail) != NULL && BEI(e)->bei_refcnt == 0 ) {
#ifdef LDAP_RDWR_DEBUG
assert(!ldap_pvt_thread_rdwr_active(&BEI(e)->bei_rdwr));
}
- /* free cache mutex */
- ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+ /* free lru mutex */
+ ldap_pvt_thread_mutex_unlock( &cache->lru_mutex );
+ /* free cache write lock */
+ ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock );
}
#ifdef LDAP_DEBUG
-
static void
bdb_lru_print( Cache *cache )
{
e->e_dn, e->e_id, BEI(e)->bei_refcnt );
}
}
-
#endif