return NULL;
}
- cache->list_head.prev = NULL;
- cache->list_head.next = &cache->list_tail;
-
- cache->list_tail.prev = &cache->list_head;
- cache->list_tail.next = NULL;
-
ngx_rbtree_init(&cache->rbtree, &cache->sentinel,
ngx_open_file_cache_rbtree_insert_value);
+ ngx_queue_init(&cache->expire_queue);
+
cache->current = 0;
cache->max = max;
cache->inactive = inactive;
{
ngx_open_file_cache_t *cache = data;
+ ngx_queue_t *q;
ngx_cached_open_file_t *file;
ngx_log_debug0(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0,
for ( ;; ) {
- file = cache->list_tail.prev;
-
- if (file == &cache->list_head) {
- break;
+ if (ngx_queue_empty(&cache->expire_queue)) {
+ return;
}
- file->next->prev = file->prev;
- file->prev->next = file->next;
+ q = ngx_queue_last(&cache->expire_queue);
+
+ file = ngx_queue_data(q, ngx_cached_open_file_t, queue);
+
+ ngx_queue_remove(q);
ngx_rbtree_delete(&cache->rbtree, &file->node);
if (rc == 0) {
- file->next->prev = file->prev;
- file->prev->next = file->next;
+ ngx_queue_remove(&file->queue);
if (file->event || now - file->created < of->retest) {
if (file->err == 0) {
file->accessed = now;
- /* add to the inactive list head */
-
- file->next = cache->list_head.next;
- file->next->prev = file;
- file->prev = &cache->list_head;
- cache->list_head.next = file;
+ ngx_queue_insert_head(&cache->expire_queue, &file->queue);
ngx_log_debug4(NGX_LOG_DEBUG_CORE, pool->log, 0,
"cached open file: %s, fd:%d, c:%d, e:%d",
file->accessed = ngx_time();
- if (cache->list_head.next != file) {
-
- /* delete from inactive list */
-
- file->next->prev = file->prev;
- file->prev->next = file->next;
-
- /* add to the inactive list head */
+ ngx_queue_remove(&file->queue);
- file->next = cache->list_head.next;
- file->next->prev = file;
- file->prev = &cache->list_head;
- cache->list_head.next = file;
- }
+ ngx_queue_insert_head(&cache->expire_queue, &file->queue);
return;
}
ngx_log_t *log)
{
time_t now;
+ ngx_queue_t *q;
ngx_cached_open_file_t *file;
now = ngx_time();
while (n < 3) {
- file = cache->list_tail.prev;
-
- if (file == &cache->list_head) {
+ if (ngx_queue_empty(&cache->expire_queue)) {
return;
}
+ q = ngx_queue_last(&cache->expire_queue);
+
+ file = ngx_queue_data(q, ngx_cached_open_file_t, queue);
+
if (n++ != 0 && now - file->accessed <= cache->inactive) {
return;
}
- file->next->prev = file->prev;
- file->prev->next = file->next;
+ ngx_queue_remove(q);
ngx_rbtree_delete(&cache->rbtree, &file->node);
fev = ev->data;
file = fev->file;
- file->next->prev = file->prev;
- file->prev->next = file->next;
+ ngx_queue_remove(&file->queue);
ngx_rbtree_delete(&fev->cache->rbtree, &file->node);