+void
+bdb_cache_return_entry_rw( struct bdb_info *bdb, Entry *e,
+ int rw, DB_LOCK *lock )
+{
+ EntryInfo *ei;
+ int free = 0;
+
+ ei = e->e_private;
+ if ( ei && ( ei->bei_state & CACHE_ENTRY_NOT_CACHED )) {
+ bdb_cache_entryinfo_lock( ei );
+ if ( ei->bei_state & CACHE_ENTRY_NOT_CACHED ) {
+ /* Releasing the entry can only be done when
+ * we know that nobody else is using it, i.e we
+ * should have an entry_db writelock. But the
+ * flag is only set by the thread that loads the
+ * entry, and only if no other threads has found
+ * it while it was working. All other threads
+ * clear the flag, which mean that we should be
+ * the only thread using the entry if the flag
+ * is set here.
+ */
+ ei->bei_e = NULL;
+ ei->bei_state ^= CACHE_ENTRY_NOT_CACHED;
+ free = 1;
+ }
+ bdb_cache_entryinfo_unlock( ei );
+ }
+ bdb_cache_entry_db_unlock( bdb, lock );
+ if ( free ) {
+ e->e_private = NULL;
+ bdb_entry_return( e );
+ }
+}
+