~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Nginx/event/ngx_event_timer.h

Version: ~ [ nginx-0.6.26 ] ~ [ nginx-0.5.35 ] ~ [ nginx-0.5.20 ] ~ [ nginx-0.5.19 ] ~

  1 
  2 /*
  3  * Copyright (C) Igor Sysoev
  4  */
  5 
  6 
  7 #ifndef _NGX_EVENT_TIMER_H_INCLUDED_
  8 #define _NGX_EVENT_TIMER_H_INCLUDED_
  9 
 10 
 11 #include <ngx_config.h>
 12 #include <ngx_core.h>
 13 #include <ngx_event.h>
 14 
 15 
 16 #define NGX_TIMER_INFINITE  (ngx_msec_t) -1
 17 
 18 #define NGX_TIMER_LAZY_DELAY  300
 19 
 20 
 21 ngx_int_t ngx_event_timer_init(ngx_log_t *log);
 22 ngx_msec_t ngx_event_find_timer(void);
 23 void ngx_event_expire_timers(void);
 24 
 25 
 26 #if (NGX_THREADS)
 27 extern ngx_mutex_t  *ngx_event_timer_mutex;
 28 #endif
 29 
 30 
 31 extern ngx_thread_volatile ngx_rbtree_t  ngx_event_timer_rbtree;
 32 
 33 
 34 static ngx_inline void
 35 ngx_event_del_timer(ngx_event_t *ev)
 36 {
 37     ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
 38                    "event timer del: %d: %M",
 39                     ngx_event_ident(ev->data), ev->timer.key);
 40 
 41     ngx_mutex_lock(ngx_event_timer_mutex);
 42 
 43     ngx_rbtree_delete(&ngx_event_timer_rbtree, &ev->timer);
 44 
 45     ngx_mutex_unlock(ngx_event_timer_mutex);
 46 
 47 #if (NGX_DEBUG)
 48     ev->timer.left = NULL;
 49     ev->timer.right = NULL;
 50     ev->timer.parent = NULL;
 51 #endif
 52 
 53     ev->timer_set = 0;
 54 }
 55 
 56 
 57 static ngx_inline void
 58 ngx_event_add_timer(ngx_event_t *ev, ngx_msec_t timer)
 59 {
 60     ngx_msec_t      key;
 61     ngx_msec_int_t  diff;
 62 
 63     key = ngx_current_msec + timer;
 64 
 65     if (ev->timer_set) {
 66 
 67         /*
 68          * Use a previous timer value if difference between it and a new
 69          * value is less than NGX_TIMER_LAZY_DELAY milliseconds: this allows
 70          * to minimize the rbtree operations for fast connections.
 71          */
 72 
 73         diff = (ngx_msec_int_t) (key - ev->timer.key);
 74 
 75         if (ngx_abs(diff) < NGX_TIMER_LAZY_DELAY) {
 76             ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0,
 77                            "event timer: %d, old: %M, new: %M",
 78                             ngx_event_ident(ev->data), ev->timer.key, key);
 79             return;
 80         }
 81 
 82         ngx_del_timer(ev);
 83     }
 84 
 85     ev->timer.key = key;
 86 
 87     ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0,
 88                    "event timer add: %d: %M:%M",
 89                     ngx_event_ident(ev->data), timer, ev->timer.key);
 90 
 91     ngx_mutex_lock(ngx_event_timer_mutex);
 92 
 93     ngx_rbtree_insert(&ngx_event_timer_rbtree, &ev->timer);
 94 
 95     ngx_mutex_unlock(ngx_event_timer_mutex);
 96 
 97     ev->timer_set = 1;
 98 }
 99 
100 
101 #endif /* _NGX_EVENT_TIMER_H_INCLUDED_ */
102 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.