]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldbm/dbcache.c
error message from be_entry_put tool backend function
[openldap] / servers / slapd / back-ldbm / dbcache.c
index fb6472e5257dee141c52dcbf022d48b8ab567d42..1187e6b2954b667407e8abf1db5081a72838283c 100644 (file)
@@ -1,7 +1,7 @@
 /* ldbmcache.c - maintain a cache of open ldbm files */
 /* $OpenLDAP$ */
 /*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 
@@ -13,6 +13,7 @@
 #include <ac/socket.h>
 #include <ac/string.h>
 #include <ac/time.h>
+#include <ac/unistd.h>
 #include <sys/stat.h>
 
 #include "slap.h"
@@ -28,7 +29,7 @@ ldbm_cache_open(
 {
        struct ldbminfo *li = (struct ldbminfo *) be->be_private;
        int             i, lru, empty;
-       time_t          oldtime, curtime;
+       time_t          oldtime;
        char            buf[MAXPATHLEN];
 #ifdef HAVE_ST_BLKSIZE
        struct stat     st;
@@ -61,13 +62,12 @@ ldbm_cache_open(
 #endif
 
 
-       curtime = slap_get_time();
        empty = MAXDBCACHE;
 
        ldap_pvt_thread_mutex_lock( &li->li_dbcache_mutex );
        do {
                lru = 0;
-               oldtime = curtime;
+               oldtime = 1;
                for ( i = 0; i < MAXDBCACHE; i++ ) {
                        /* see if this slot is free */
                        if ( li->li_dbcache[i].dbc_name == NULL) {
@@ -113,8 +113,9 @@ ldbm_cache_open(
                        }
 
                        /* keep track of lru db */
-                       if ( li->li_dbcache[i].dbc_lastref < oldtime
-                               && li->li_dbcache[i].dbc_refcnt == 0 )
+                       if (( li->li_dbcache[i].dbc_refcnt == 0 ) &&
+                             (( oldtime == 1 ) ||
+                             ( li->li_dbcache[i].dbc_lastref < oldtime )) )
                        {
                                lru = i;
                                oldtime = li->li_dbcache[i].dbc_lastref;
@@ -170,7 +171,7 @@ ldbm_cache_open(
        }
        li->li_dbcache[i].dbc_name = ch_strdup( buf );
        li->li_dbcache[i].dbc_refcnt = 1;
-       li->li_dbcache[i].dbc_lastref = curtime;
+       li->li_dbcache[i].dbc_lastref = slap_get_time();
        li->li_dbcache[i].dbc_flags = flags;
        li->li_dbcache[i].dbc_dirty = 0;
 #ifdef HAVE_ST_BLKSIZE
@@ -207,6 +208,8 @@ ldbm_cache_open(
        Debug( LDAP_DEBUG_TRACE, "<= ldbm_cache_open (opened %d)\n", i, 0, 0 );
 #endif
 
+       ldap_pvt_thread_mutex_init( &li->li_dbcache[i].dbc_write_mutex );
+
        ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex );
        return( &li->li_dbcache[i] );
 }
@@ -241,6 +244,7 @@ ldbm_cache_really_close( Backend *be, DBCache *db )
                ldbm_close( db->dbc_db );
                free( db->dbc_name );
                db->dbc_name = NULL;
+               ldap_pvt_thread_mutex_destroy( &db->dbc_write_mutex );
        }
        ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex );
 }
@@ -322,11 +326,7 @@ ldbm_cache_fetch(
     Datum              key
 )
 {
-       Datum   data;
-
        return ldbm_fetch( db->dbc_db, key );
-
-       return( data );
 }
 
 int