Commit c73520ec authored by Pierangelo Masarati's avatar Pierangelo Masarati
Browse files

fix idl lru deletion of last entry (ITS#5121)

parent 1800fbb3
...@@ -27,11 +27,24 @@ ...@@ -27,11 +27,24 @@
#define IDL_CMP(x,y) ( x < y ? -1 : ( x > y ? 1 : 0 ) ) #define IDL_CMP(x,y) ( x < y ? -1 : ( x > y ? 1 : 0 ) )
#define IDL_LRU_DELETE( bdb, e ) do { \ #define IDL_LRU_DELETE( bdb, e ) do { \
if ( e == bdb->bi_idl_lru_head ) bdb->bi_idl_lru_head = e->idl_lru_next; \ if ( (e) == (bdb)->bi_idl_lru_head ) { \
if ( e == bdb->bi_idl_lru_tail ) bdb->bi_idl_lru_tail = e->idl_lru_prev; \ if ( (e)->idl_lru_next == (bdb)->bi_idl_lru_head ) { \
e->idl_lru_next->idl_lru_prev = e->idl_lru_prev; \ (bdb)->bi_idl_lru_head = NULL; \
e->idl_lru_prev->idl_lru_next = e->idl_lru_next; \ } else { \
(bdb)->bi_idl_lru_head = (e)->idl_lru_next; \
} \
} \
if ( (e) == (bdb)->bi_idl_lru_tail ) { \
if ( (e)->idl_lru_prev == (bdb)->bi_idl_lru_tail ) { \
assert( (bdb)->bi_idl_lru_head == NULL ); \
(bdb)->bi_idl_lru_tail = NULL; \
} else { \
(bdb)->bi_idl_lru_tail = (e)->idl_lru_prev; \
} \
} \
(e)->idl_lru_next->idl_lru_prev = (e)->idl_lru_prev; \
(e)->idl_lru_prev->idl_lru_next = (e)->idl_lru_next; \
} while ( 0 ) } while ( 0 )
static int static int
...@@ -349,6 +362,10 @@ bdb_idl_cache_put( ...@@ -349,6 +362,10 @@ bdb_idl_cache_put(
ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_lrulock ); ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_lrulock );
/* LRU_ADD */ /* LRU_ADD */
if ( bdb->bi_idl_lru_head ) { if ( bdb->bi_idl_lru_head ) {
assert( bdb->bi_idl_lru_tail != NULL );
assert( bdb->bi_idl_lru_head->idl_lru_prev != NULL );
assert( bdb->bi_idl_lru_head->idl_lru_next != NULL );
ee->idl_lru_next = bdb->bi_idl_lru_head; ee->idl_lru_next = bdb->bi_idl_lru_head;
ee->idl_lru_prev = bdb->bi_idl_lru_head->idl_lru_prev; ee->idl_lru_prev = bdb->bi_idl_lru_head->idl_lru_prev;
bdb->bi_idl_lru_head->idl_lru_prev->idl_lru_next = ee; bdb->bi_idl_lru_head->idl_lru_prev->idl_lru_next = ee;
...@@ -364,6 +381,9 @@ bdb_idl_cache_put( ...@@ -364,6 +381,9 @@ bdb_idl_cache_put(
ee = bdb->bi_idl_lru_tail; ee = bdb->bi_idl_lru_tail;
for ( i = 0; i < 10; i++, ee = eprev ) { for ( i = 0; i < 10; i++, ee = eprev ) {
eprev = ee->idl_lru_prev; eprev = ee->idl_lru_prev;
if ( eprev == ee ) {
eprev = NULL;
}
if ( ee->idl_flags & CACHE_ENTRY_REFERENCED ) { if ( ee->idl_flags & CACHE_ENTRY_REFERENCED ) {
ee->idl_flags ^= CACHE_ENTRY_REFERENCED; ee->idl_flags ^= CACHE_ENTRY_REFERENCED;
continue; continue;
...@@ -382,6 +402,8 @@ bdb_idl_cache_put( ...@@ -382,6 +402,8 @@ bdb_idl_cache_put(
ch_free( ee ); ch_free( ee );
} }
bdb->bi_idl_lru_tail = eprev; bdb->bi_idl_lru_tail = eprev;
assert( bdb->bi_idl_lru_tail != NULL
|| bdb->bi_idl_lru_head == NULL );
} }
ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_lrulock ); ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_lrulock );
ldap_pvt_thread_rdwr_wunlock( &bdb->bi_idl_tree_rwlock ); ldap_pvt_thread_rdwr_wunlock( &bdb->bi_idl_tree_rwlock );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment