Klaus Demo nginx / 181abe5
embed session_rbtree and sentinel inside ngx_ssl_session_cache_t Igor Sysoev 14 years ago
2 changed file(s) with 13 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
12161216 ngx_ssl_session_cache_init(ngx_shm_zone_t *shm_zone, void *data)
12171217 {
12181218 ngx_slab_pool_t *shpool;
1219 ngx_rbtree_node_t *sentinel;
12201219 ngx_ssl_session_cache_t *cache;
12211220
12221221 if (data) {
12311230 return NGX_ERROR;
12321231 }
12331232
1233 ngx_rbtree_init(&cache->session_rbtree, &cache->sentinel,
1234 ngx_ssl_session_rbtree_insert_value);
1235
12341236 cache->session_cache_head.prev = NULL;
12351237 cache->session_cache_head.next = &cache->session_cache_tail;
12361238
12371239 cache->session_cache_tail.prev = &cache->session_cache_head;
12381240 cache->session_cache_tail.next = NULL;
1239
1240 cache->session_rbtree = ngx_slab_alloc(shpool, sizeof(ngx_rbtree_t));
1241 if (cache->session_rbtree == NULL) {
1242 return NGX_ERROR;
1243 }
1244
1245 sentinel = ngx_slab_alloc(shpool, sizeof(ngx_rbtree_node_t));
1246 if (sentinel == NULL) {
1247 return NGX_ERROR;
1248 }
1249
1250 ngx_rbtree_init(cache->session_rbtree, sentinel,
1251 ngx_ssl_session_rbtree_insert_value);
12521241
12531242 shm_zone->data = cache;
12541243
13681357 sess_id->prev = &cache->session_cache_head;
13691358 cache->session_cache_head.next = sess_id;
13701359
1371 ngx_rbtree_insert(cache->session_rbtree, &sess_id->node);
1360 ngx_rbtree_insert(&cache->session_rbtree, &sess_id->node);
13721361
13731362 ngx_shmtx_unlock(&shpool->mutex);
13741363
14311420
14321421 ngx_shmtx_lock(&shpool->mutex);
14331422
1434 node = cache->session_rbtree->root;
1435 sentinel = cache->session_rbtree->sentinel;
1423 node = cache->session_rbtree.root;
1424 sentinel = cache->session_rbtree.sentinel;
14361425
14371426 while (node != sentinel) {
14381427
14691458 sess_id->next->prev = sess_id->prev;
14701459 sess_id->prev->next = sess_id->next;
14711460
1472 ngx_rbtree_delete(cache->session_rbtree, node);
1461 ngx_rbtree_delete(&cache->session_rbtree, node);
14731462
14741463 ngx_slab_free_locked(shpool, sess_id->session);
14751464 #if (NGX_PTR_SIZE == 4)
15261515
15271516 ngx_shmtx_lock(&shpool->mutex);
15281517
1529 node = cache->session_rbtree->root;
1530 sentinel = cache->session_rbtree->sentinel;
1518 node = cache->session_rbtree.root;
1519 sentinel = cache->session_rbtree.sentinel;
15311520
15321521 while (node != sentinel) {
15331522
15521541 sess_id->next->prev = sess_id->prev;
15531542 sess_id->prev->next = sess_id->next;
15541543
1555 ngx_rbtree_delete(cache->session_rbtree, node);
1544 ngx_rbtree_delete(&cache->session_rbtree, node);
15561545
15571546 ngx_slab_free_locked(shpool, sess_id->session);
15581547 #if (NGX_PTR_SIZE == 4)
16001589 sess_id->next->prev = sess_id->prev;
16011590 sess_id->prev->next = sess_id->next;
16021591
1603 ngx_rbtree_delete(cache->session_rbtree, &sess_id->node);
1592 ngx_rbtree_delete(&cache->session_rbtree, &sess_id->node);
16041593
16051594 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ngx_cycle->log, 0,
16061595 "expire session: %08Xi", sess_id->node.key);
7474
7575
7676 typedef struct {
77 ngx_rbtree_t *session_rbtree;
77 ngx_rbtree_t session_rbtree;
78 ngx_rbtree_node_t sentinel;
7879 ngx_ssl_sess_id_t session_cache_head;
7980 ngx_ssl_sess_id_t session_cache_tail;
8081 } ngx_ssl_session_cache_t;