/* cache.c - routines to maintain an in-core cache of entries */
+#include "portable.h"
+
#include <stdio.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+int strcasecmp( const char *, const char *);
+
+#include <ac/socket.h>
#include "slap.h"
+
#include "back-ldbm.h"
-static int cache_delete_entry_internal();
+static int cache_delete_entry_internal(struct cache *cache, Entry *e);
#ifdef LDAP_DEBUG
-static void lru_print();
+static void lru_print(struct cache *cache);
#endif
/*
cache_entrydn_cmp, avl_dup_error ) != 0 )
{
Debug( LDAP_DEBUG_TRACE,
- "====> cache_add_entry lock: entry %20s id %d already in dn cache\n",
+ "====> cache_add_entry lock: entry %20s id %lu already in dn cache\n",
e->e_dn, e->e_id, 0 );
/* free cache mutex */
cache_entryid_cmp, avl_dup_error ) != 0 )
{
Debug( LDAP_DEBUG_ANY,
- "====> entry %20s id %d already in id cache\n",
+ "====> entry %20s id %lu already in id cache\n",
e->e_dn, e->e_id, 0 );
/* delete from dn tree inserted above */
e = cache->c_lrutail;
/* XXX check for writer lock - should also check no readers pending */
- assert(pthread_rdwr_wchk_np(&e->e_rdwr));
+#ifdef LDAP_DEBUG
+ assert(!pthread_rdwr_rwchk_np(&e->e_rdwr));
+#endif
/* delete from cache and lru q */
rc = cache_delete_entry_internal( cache, e );
Debug( LDAP_DEBUG_TRACE, "====> cache_delete_entry:\n", 0, 0, 0 );
/* XXX check for writer lock - should also check no readers pending */
+#ifdef LDAP_DEBUG
assert(pthread_rdwr_wchk_np(&e->e_rdwr));
+#endif
/* set cache mutex */
pthread_mutex_lock( &cache->c_mutex );
Entry *e
)
{
+ int rc = 0; /* return code */
+
/* dn tree */
if ( avl_delete( &cache->c_dntree, (caddr_t) e, cache_entrydn_cmp )
== NULL )
{
- return( -1 );
+ rc = -1;
}
/* id tree */
if ( avl_delete( &cache->c_idtree, (caddr_t) e, cache_entryid_cmp )
== NULL )
{
- return( -1 );
+ rc = -1;
+ }
+
+ if (rc != 0) {
+ return rc;
}
/* lru */
fprintf( stderr, "LRU queue (head to tail):\n" );
for ( e = cache->c_lruhead; e != NULL; e = e->e_lrunext ) {
- fprintf( stderr, "\tdn %20s id %d refcnt %d\n", e->e_dn,
+ fprintf( stderr, "\tdn %20s id %lu refcnt %d\n", e->e_dn,
e->e_id, e->e_refcnt );
}
fprintf( stderr, "LRU queue (tail to head):\n" );
for ( e = cache->c_lrutail; e != NULL; e = e->e_lruprev ) {
- fprintf( stderr, "\tdn %20s id %d refcnt %d\n", e->e_dn,
+ fprintf( stderr, "\tdn %20s id %lu refcnt %d\n", e->e_dn,
e->e_id, e->e_refcnt );
}
}