+ LDAP_LOG( CACHE, DETAIL1,
+ "bdb_unlocked_cache_return_entry_rw: return (%ld):%s, refcnt=%d\n",
+ id, rw ? "w" : "r", refcnt );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "====> bdb_unlocked_cache_return_entry_%s( %ld ): created (%d)\n",
+ rw ? "w" : "r", id, refcnt );
+#endif
+
+
+ } else if ( BEI(e)->bei_state == CACHE_ENTRY_DELETED ) {
+ if( refcnt > 0 ) {
+ /* free cache write lock */
+ ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock );
+
+#ifdef NEW_LOGGING
+ LDAP_LOG( CACHE, DETAIL1,
+ "bdb_unlocked_cache_return_entry_rw: %ld, delete pending (%d).\n",
+ id, refcnt, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "====> bdb_unlocked_cache_return_entry_%s( %ld ): delete pending (%d)\n",
+ rw ? "w" : "r", id, refcnt );
+#endif
+
+ } else {
+ bdb_cache_entry_private_destroy( e );
+ if ( freeit ) {
+ bdb_entry_return( e );
+ }
+
+ /* free cache write lock */
+ ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock );
+
+#ifdef NEW_LOGGING
+ LDAP_LOG( CACHE, DETAIL1,
+ "bdb_unlocked_cache_return_entry_rw: (%ld): deleted (%d)\n",
+ id, refcnt, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "====> bdb_unlocked_cache_return_entry_%s( %ld ): deleted (%d)\n",
+ rw ? "w" : "r", id, refcnt );
+#endif
+ }
+
+ } else {
+ /* free cache write lock */
+ ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock );
+
+#ifdef NEW_LOGGING
+ LDAP_LOG( CACHE, DETAIL1,
+ "bdb_unlocked_cache_return_entry_rw: ID %ld:%s returned (%d)\n",
+ id, rw ? "w": "r", refcnt );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "====> bdb_unlocked_cache_return_entry_%s( %ld ): returned (%d)\n",
+ rw ? "w" : "r", id, refcnt);
+#endif
+ }
+}
+
+void
+bdb_cache_return_entry_rw
+( DB_ENV *env, Cache *cache, Entry *e, int rw, DB_LOCK *lock )
+{
+ ID id;
+ int refcnt, freeit = 1;
+
+ /* set cache write lock */
+ ldap_pvt_thread_rdwr_wlock( &cache->c_rwlock );
+
+ assert( e->e_private );
+
+ bdb_cache_entry_db_unlock( env, lock );
+#if 0
+ bdb_cache_entry_rdwr_unlock(e, rw);
+#endif
+
+ id = e->e_id;
+ refcnt = --BEI(e)->bei_refcnt;
+
+ /*
+ * if the entry is returned when in CREATING state, it is deleted
+ * but not freed because it may belong to someone else (do_add,
+ * 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 write lock */
+ ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock );
+
+#ifdef NEW_LOGGING
+ LDAP_LOG( CACHE, DETAIL1,