comparison src/event/ngx_event_timer.c @ 5894:1f513d7f1b45

Events: removed broken thread support from event timers. It's mostly dead code. And the idea of thread support for this task has been deprecated.
author Valentin Bartenev <vbart@nginx.com>
date Mon, 25 Aug 2014 13:34:39 +0400
parents 3377f9459e99
children 0f53e5fb7205
comparison
equal deleted inserted replaced
5893:fa4161fe8254 5894:1f513d7f1b45
8 #include <ngx_config.h> 8 #include <ngx_config.h>
9 #include <ngx_core.h> 9 #include <ngx_core.h>
10 #include <ngx_event.h> 10 #include <ngx_event.h>
11 11
12 12
13 #if (NGX_THREADS) 13 ngx_rbtree_t ngx_event_timer_rbtree;
14 ngx_mutex_t *ngx_event_timer_mutex; 14 static ngx_rbtree_node_t ngx_event_timer_sentinel;
15 #endif
16
17
18 ngx_thread_volatile ngx_rbtree_t ngx_event_timer_rbtree;
19 static ngx_rbtree_node_t ngx_event_timer_sentinel;
20 15
21 /* 16 /*
22 * the event timer rbtree may contain the duplicate keys, however, 17 * the event timer rbtree may contain the duplicate keys, however,
23 * it should not be a problem, because we use the rbtree to find 18 * it should not be a problem, because we use the rbtree to find
24 * a minimum timer value only 19 * a minimum timer value only
27 ngx_int_t 22 ngx_int_t
28 ngx_event_timer_init(ngx_log_t *log) 23 ngx_event_timer_init(ngx_log_t *log)
29 { 24 {
30 ngx_rbtree_init(&ngx_event_timer_rbtree, &ngx_event_timer_sentinel, 25 ngx_rbtree_init(&ngx_event_timer_rbtree, &ngx_event_timer_sentinel,
31 ngx_rbtree_insert_timer_value); 26 ngx_rbtree_insert_timer_value);
32
33 #if (NGX_THREADS)
34
35 if (ngx_event_timer_mutex) {
36 ngx_event_timer_mutex->log = log;
37 return NGX_OK;
38 }
39
40 ngx_event_timer_mutex = ngx_mutex_init(log, 0);
41 if (ngx_event_timer_mutex == NULL) {
42 return NGX_ERROR;
43 }
44
45 #endif
46 27
47 return NGX_OK; 28 return NGX_OK;
48 } 29 }
49 30
50 31
56 37
57 if (ngx_event_timer_rbtree.root == &ngx_event_timer_sentinel) { 38 if (ngx_event_timer_rbtree.root == &ngx_event_timer_sentinel) {
58 return NGX_TIMER_INFINITE; 39 return NGX_TIMER_INFINITE;
59 } 40 }
60 41
61 ngx_mutex_lock(ngx_event_timer_mutex);
62
63 root = ngx_event_timer_rbtree.root; 42 root = ngx_event_timer_rbtree.root;
64 sentinel = ngx_event_timer_rbtree.sentinel; 43 sentinel = ngx_event_timer_rbtree.sentinel;
65 44
66 node = ngx_rbtree_min(root, sentinel); 45 node = ngx_rbtree_min(root, sentinel);
67
68 ngx_mutex_unlock(ngx_event_timer_mutex);
69 46
70 timer = (ngx_msec_int_t) (node->key - ngx_current_msec); 47 timer = (ngx_msec_int_t) (node->key - ngx_current_msec);
71 48
72 return (ngx_msec_t) (timer > 0 ? timer : 0); 49 return (ngx_msec_t) (timer > 0 ? timer : 0);
73 } 50 }
80 ngx_rbtree_node_t *node, *root, *sentinel; 57 ngx_rbtree_node_t *node, *root, *sentinel;
81 58
82 sentinel = ngx_event_timer_rbtree.sentinel; 59 sentinel = ngx_event_timer_rbtree.sentinel;
83 60
84 for ( ;; ) { 61 for ( ;; ) {
85
86 ngx_mutex_lock(ngx_event_timer_mutex);
87
88 root = ngx_event_timer_rbtree.root; 62 root = ngx_event_timer_rbtree.root;
89 63
90 if (root == sentinel) { 64 if (root == sentinel) {
91 return; 65 return;
92 } 66 }
102 "event timer del: %d: %M", 76 "event timer del: %d: %M",
103 ngx_event_ident(ev->data), ev->timer.key); 77 ngx_event_ident(ev->data), ev->timer.key);
104 78
105 ngx_rbtree_delete(&ngx_event_timer_rbtree, &ev->timer); 79 ngx_rbtree_delete(&ngx_event_timer_rbtree, &ev->timer);
106 80
107 ngx_mutex_unlock(ngx_event_timer_mutex);
108
109 #if (NGX_DEBUG) 81 #if (NGX_DEBUG)
110 ev->timer.left = NULL; 82 ev->timer.left = NULL;
111 ev->timer.right = NULL; 83 ev->timer.right = NULL;
112 ev->timer.parent = NULL; 84 ev->timer.parent = NULL;
113 #endif 85 #endif
121 continue; 93 continue;
122 } 94 }
123 95
124 break; 96 break;
125 } 97 }
126
127 ngx_mutex_unlock(ngx_event_timer_mutex);
128 } 98 }