- /* if parent was previously considered a leaf node,
- * it was on the LRU list. Now it's going to have
- * kids, take it off the LRU list.
- */
- ldap_pvt_thread_mutex_lock( &cache->lru_mutex );
- if ( ei->bei_parent->bei_id && !ei->bei_parent->bei_kids ) {
- LRU_DELETE( cache, ei->bei_parent );
- incr = 0;
- }
-
- cache->c_cursize += incr;
-
- /* See if we're above the cache size limit */
- if ( cache->c_cursize > cache->c_maxsize ) {
- EntryInfo *elru, *elprev;
- int i = 0;
-
- /* Look for an unused entry to remove */
- for (elru = cache->c_lrutail; elru; elru = elprev, i++ ) {
- elprev = elru->bei_lruprev;
-
- /* Too many probes, not enough idle, give up */
- if (i > 10) break;
-
- /* If we can successfully writelock it, then
- * the object is idle.
- */
- if ( bdb_cache_entry_db_lock( env, locker, elru, 1, 1,
- &lock ) == 0 ) {
- /* Need to lock parent to delete child */
- if ( ldap_pvt_thread_mutex_trylock(
- &elru->bei_parent->bei_kids_mutex )) {
- bdb_cache_entry_db_unlock( env, &lock );
- continue;
- }
- bdb_cache_delete_internal( cache, elru );
- bdb_cache_entryinfo_unlock( elru->bei_parent );
- elru->bei_e->e_private = NULL;
- bdb_entry_return( elru->bei_e );
- bdb_cache_entry_db_unlock( env, &lock );
- if (ei2) {
- bdb_cache_entryinfo_destroy( elru );
- } else {
- /* re-use this one */
- ch_free(elru->bei_nrdn.bv_val);
- elru->bei_nrdn.bv_val = NULL;
- elru->bei_e = NULL;
- elru->bei_kids = NULL;
- elru->bei_lrunext = NULL;
- elru->bei_lruprev = NULL;
- elru->bei_state = 0;
-#ifdef BDB_HIER
- ch_free(elru->bei_rdn.bv_val);
- elru->bei_rdn.bv_val = NULL;
- elru->bei_modrdns = 0;
-#endif
- ei2 = elru;
- }
- if (cache->c_cursize < cache->c_maxsize)
- break;
- }
- }
- }
- if (!ei2) {
- ei2 = bdb_cache_entryinfo_new();
- }