]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldbm/cache.c
Code clean-up.
[openldap] / servers / slapd / back-ldbm / cache.c
index a1877e073867e33a2729b52c3704d2342f112fcc..fe88ed895d12137675094cd0729d164d6dcf5953 100644 (file)
@@ -38,24 +38,10 @@ static int  cache_delete_entry_internal(struct cache *cache, Entry *e);
 static void    lru_print(struct cache *cache);
 #endif
 
-/*
- * the cache has three entry points (ways to find things):
- *
- *     by entry        e.g., if you already have an entry from the cache
- *                     and want to delete it. (really by entry ptr)
- *     by dn           e.g., when looking for the base object of a search
- *     by id           e.g., for search candidates
- *
- * these correspond to three different avl trees that are maintained.
- */
-#define cache_entry_cmp entry_cmp
-#define cache_entrydn_cmp entry_dn_cmp
-#define cache_entryid_cmp entry_id_cmp
-
 static int
 cache_entry_rdwr_lock(Entry *e, int rw)
 {
-       Debug( LDAP_DEBUG_ARGS, "entry_rdwr_%slock: ID: %lu\n",
+       Debug( LDAP_DEBUG_ARGS, "entry_rdwr_%slock: ID: %ld\n",
                rw ? "w" : "r", e->e_id, 0);
 
        if (rw)
@@ -67,7 +53,7 @@ cache_entry_rdwr_lock(Entry *e, int rw)
 static int
 cache_entry_rdwr_trylock(Entry *e, int rw)
 {
-       Debug( LDAP_DEBUG_ARGS, "entry_rdwr_%strylock: ID: %lu\n",
+       Debug( LDAP_DEBUG_ARGS, "entry_rdwr_%strylock: ID: %ld\n",
                rw ? "w" : "r", e->e_id, 0);
 
        if (rw)
@@ -79,7 +65,7 @@ cache_entry_rdwr_trylock(Entry *e, int rw)
 static int
 cache_entry_rdwr_unlock(Entry *e, int rw)
 {
-       Debug( LDAP_DEBUG_ARGS, "entry_rdwr_%sunlock: ID: %lu\n",
+       Debug( LDAP_DEBUG_ARGS, "entry_rdwr_%sunlock: ID: %ld\n",
                rw ? "w" : "r", e->e_id, 0);
 
        if (rw)
@@ -157,7 +143,7 @@ cache_return_entry_rw( struct cache *cache, Entry *e, int rw )
 
        if ( LEI(e)->lei_state == CACHE_ENTRY_CREATING ) {
                Debug( LDAP_DEBUG_TRACE,
-                       "====> cache_return_entry_%s( %lu ): created (%d)\n",
+                       "====> cache_return_entry_%s( %ld ): created (%d)\n",
                        rw ? "w" : "r", e->e_id, LEI(e)->lei_refcnt );
 
                LEI(e)->lei_state = CACHE_ENTRY_READY;
@@ -165,12 +151,12 @@ cache_return_entry_rw( struct cache *cache, Entry *e, int rw )
        } else if ( LEI(e)->lei_state == CACHE_ENTRY_DELETED ) {
                if( LEI(e)->lei_refcnt > 0 ) {
                        Debug( LDAP_DEBUG_TRACE,
-                               "====> cache_return_entry_%s( %lu ): delete pending (%d)\n",
+                               "====> cache_return_entry_%s( %ld ): delete pending (%d)\n",
                                rw ? "w" : "r", e->e_id, LEI(e)->lei_refcnt );
 
                } else {
                        Debug( LDAP_DEBUG_TRACE,
-                               "====> cache_return_entry_%s( %lu ): deleted (%d)\n",
+                               "====> cache_return_entry_%s( %ld ): deleted (%d)\n",
                                rw ? "w" : "r", e->e_id, LEI(e)->lei_refcnt );
 
                        cache_entry_private_destroy( e );
@@ -179,7 +165,7 @@ cache_return_entry_rw( struct cache *cache, Entry *e, int rw )
 
        } else {
                Debug( LDAP_DEBUG_TRACE,
-                       "====> cache_return_entry_%s( %lu ): returned (%d)\n",
+                       "====> cache_return_entry_%s( %ld ): returned (%d)\n",
                        rw ? "w" : "r", e->e_id, LEI(e)->lei_refcnt);
        }
 
@@ -238,16 +224,16 @@ cache_add_entry_rw(
 
        if( cache_entry_private_init(e) != 0 ) {
                Debug( LDAP_DEBUG_ANY,
-                       "====> cache_add_entry( %lu ): \"%s\": private init failed!\n",
+                       "====> cache_add_entry( %ld ): \"%s\": private init failed!\n",
                    e->e_id, e->e_dn, 0 );
                return( -1 );
        }
 
        if ( avl_insert( &cache->c_dntree, (caddr_t) e,
-               cache_entrydn_cmp, avl_dup_error ) != 0 )
+               entry_dn_cmp, avl_dup_error ) != 0 )
        {
                Debug( LDAP_DEBUG_TRACE,
-                       "====> cache_add_entry( %lu ): \"%s\": already in dn cache\n",
+                       "====> cache_add_entry( %ld ): \"%s\": already in dn cache\n",
                    e->e_id, e->e_dn, 0 );
 
                cache_entry_private_destroy(e);
@@ -259,16 +245,16 @@ cache_add_entry_rw(
 
        /* id tree */
        if ( avl_insert( &cache->c_idtree, (caddr_t) e,
-               cache_entryid_cmp, avl_dup_error ) != 0 )
+               entry_id_cmp, avl_dup_error ) != 0 )
        {
                Debug( LDAP_DEBUG_ANY,
-                       "====> cache_add_entry( %lu ): \"%s\": already in id cache\n",
+                       "====> cache_add_entry( %ld ): \"%s\": already in id cache\n",
                    e->e_id, e->e_dn, 0 );
 
 
                /* delete from dn tree inserted above */
                if ( avl_delete( &cache->c_dntree, (caddr_t) e,
-                       cache_entrydn_cmp ) == NULL )
+                       entry_dn_cmp ) == NULL )
                {
                        Debug( LDAP_DEBUG_ANY, "====> can't delete from dn cache\n",
                            0, 0, 0 );
@@ -319,6 +305,7 @@ cache_add_entry_rw(
                        e = cache->c_lrutail;
 
                        /* delete from cache and lru q */
+                       /* XXX do we need rc ? */
                        rc = cache_delete_entry_internal( cache, e );
                        cache_entry_private_destroy( e );
                        entry_free( e );
@@ -353,10 +340,10 @@ cache_update_entry(
 #endif
 
        if ( avl_insert( &cache->c_dntree, (caddr_t) e,
-               cache_entrydn_cmp, avl_dup_error ) != 0 )
+               entry_dn_cmp, avl_dup_error ) != 0 )
        {
                Debug( LDAP_DEBUG_TRACE,
-                       "====> cache_update_entry( %lu ): \"%s\": already in dn cache\n",
+                       "====> cache_update_entry( %ld ): \"%s\": already in dn cache\n",
                    e->e_id, e->e_dn, 0 );
 
                /* free cache mutex */
@@ -366,15 +353,15 @@ cache_update_entry(
 
        /* id tree */
        if ( avl_insert( &cache->c_idtree, (caddr_t) e,
-               cache_entryid_cmp, avl_dup_error ) != 0 )
+               entry_id_cmp, avl_dup_error ) != 0 )
        {
                Debug( LDAP_DEBUG_ANY,
-                       "====> cache_update_entry( %lu ): \"%s\": already in id cache\n",
+                       "====> cache_update_entry( %ld ): \"%s\": already in id cache\n",
                    e->e_id, e->e_dn, 0 );
 
                /* delete from dn tree inserted above */
                if ( avl_delete( &cache->c_dntree, (caddr_t) e,
-                       cache_entrydn_cmp ) == NULL )
+                       entry_dn_cmp ) == NULL )
                {
                        Debug( LDAP_DEBUG_ANY, "====> can't delete from dn cache\n",
                            0, 0, 0 );
@@ -421,6 +408,7 @@ cache_update_entry(
                        e = cache->c_lrutail;
 
                        /* delete from cache and lru q */
+                       /* XXX do we need rc ? */
                        rc = cache_delete_entry_internal( cache, e );
                        cache_entry_private_destroy( e );
                        entry_free( e );
@@ -454,7 +442,7 @@ cache_find_entry_dn2id(
        e.e_ndn = dn_normalize_case( ch_strdup( dn ) );
 
        if ( (ep = (Entry *) avl_find( cache->c_dntree, (caddr_t) &e,
-               cache_entrydn_cmp )) != NULL )
+               entry_dn_cmp )) != NULL )
        {
                /*
                 * ep now points to an unlocked entry
@@ -474,7 +462,7 @@ cache_find_entry_dn2id(
                        assert(LEI(ep)->lei_state != CACHE_ENTRY_UNDEFINED);
 #endif
                        Debug(LDAP_DEBUG_TRACE,
-                               "====> cache_find_entry_dn2id(\"%s\"): %lu (not ready) %d\n",
+                               "====> cache_find_entry_dn2id(\"%s\"): %ld (not ready) %d\n",
                                dn, ep->e_id, LEI(ep)->lei_state);
 
                        /* free cache mutex */
@@ -483,7 +471,7 @@ cache_find_entry_dn2id(
                }
 
                Debug(LDAP_DEBUG_TRACE,
-                       "====> cache_find_entry_dn2id(\"%s\"): %lu\n",
+                       "====> cache_find_entry_dn2id(\"%s\"): %ld\n",
                        dn, ep->e_id, 0);
 
                /* lru */
@@ -528,7 +516,7 @@ try_again:
        ldap_pvt_thread_mutex_lock( &cache->c_mutex );
 
        if ( (ep = (Entry *) avl_find( cache->c_idtree, (caddr_t) &e,
-               cache_entryid_cmp )) != NULL )
+               entry_id_cmp )) != NULL )
        {
 #ifdef LDAP_DEBUG
                assert( ep->e_private );
@@ -541,7 +529,7 @@ try_again:
                        assert(LEI(ep)->lei_state != CACHE_ENTRY_UNDEFINED);
 #endif
                        Debug(LDAP_DEBUG_TRACE,
-                               "====> cache_find_entry_id( %lu ): %lu (not ready) %d\n",
+                               "====> cache_find_entry_id( %ld ): %ld (not ready) %d\n",
                                id, ep->e_id, LEI(ep)->lei_state);
 
                        /* free cache mutex */
@@ -550,7 +538,7 @@ try_again:
                }
 
                Debug(LDAP_DEBUG_TRACE,
-                       "====> cache_find_entry_id( %lu, %s ) \"%s\" (found)\n",
+                       "====> cache_find_entry_id( %ld, %s ) \"%s\" (found)\n",
                        id, rw ? "w" : "r", ep->e_dn);
 
                /* acquire reader lock */
@@ -610,7 +598,7 @@ cache_delete_entry(
        assert( e->e_private );
 #endif
 
-       Debug( LDAP_DEBUG_TRACE, "====> cache_delete_entry( %lu )\n",
+       Debug( LDAP_DEBUG_TRACE, "====> cache_delete_entry( %ld )\n",
                e->e_id, 0, 0 );
 
        rc = cache_delete_entry_internal( cache, e );
@@ -629,14 +617,14 @@ cache_delete_entry_internal(
        int rc = 0;     /* return code */
 
        /* dn tree */
-       if ( avl_delete( &cache->c_dntree, (caddr_t) e, cache_entrydn_cmp )
+       if ( avl_delete( &cache->c_dntree, (caddr_t) e, entry_dn_cmp )
                == NULL )
        {
                rc = -1;
        }
 
        /* id tree */
-       if ( avl_delete( &cache->c_idtree, (caddr_t) e, cache_entryid_cmp )
+       if ( avl_delete( &cache->c_idtree, (caddr_t) e, entry_id_cmp )
                == NULL )
        {
                rc = -1;
@@ -667,12 +655,12 @@ lru_print( struct cache *cache )
 
        fprintf( stderr, "LRU queue (head to tail):\n" );
        for ( e = cache->c_lruhead; e != NULL; e = LEI(e)->lei_lrunext ) {
-               fprintf( stderr, "\tdn \"%20s\" id %lu refcnt %d\n",
+               fprintf( stderr, "\tdn \"%20s\" id %ld refcnt %d\n",
                        e->e_dn, e->e_id, LEI(e)->lei_refcnt );
        }
        fprintf( stderr, "LRU queue (tail to head):\n" );
        for ( e = cache->c_lrutail; e != NULL; e = LEI(e)->lei_lruprev ) {
-               fprintf( stderr, "\tdn \"%20s\" id %lu refcnt %d\n",
+               fprintf( stderr, "\tdn \"%20s\" id %ld refcnt %d\n",
                        e->e_dn, e->e_id, LEI(e)->lei_refcnt );
        }
 }