| 144 | } |
| 145 | |
| 146 | acl_int64 event_timer_request(ACL_EVENT *eventp, ACL_EVENT_NOTIFY_TIME callback, |
| 147 | void *context, acl_int64 delay, int keep) |
| 148 | { |
| 149 | TIMER_INFO *info; |
| 150 | TIMER_NODE *node, iter; |
| 151 | BUILD_KEY(callback, context); |
| 152 | |
| 153 | /* Make sure we schedule this event at the right time. */ |
| 154 | SET_TIME(eventp->present); |
| 155 | |
| 156 | /** |
| 157 | * See if they are resetting an existing timer request. If so, take the |
| 158 | * request away from the timer queue so that it can be inserted at the |
| 159 | * right place. |
| 160 | */ |
| 161 | |
| 162 | info = (TIMER_INFO*) acl_htable_find(eventp->timers->table, key); |
| 163 | if (info == NULL) { |
| 164 | /* If not found, schedule a new timer request. */ |
| 165 | info = (TIMER_INFO *) acl_mycalloc(1, sizeof(TIMER_INFO)); |
| 166 | acl_assert(info); |
| 167 | info->delay = delay; |
| 168 | info->keep = keep; |
| 169 | info->callback = callback; |
| 170 | info->context = context; |
| 171 | info->event_type = ACL_EVENT_TIME; |
| 172 | acl_ring_init(&info->tmp); |
| 173 | info->entry = acl_htable_enter(eventp->timers->table, key, info); |
| 174 | } else { |
| 175 | info->delay = delay; |
| 176 | info->keep = keep; |
| 177 | node_unlink(eventp, info); |
| 178 | } |
| 179 | |
| 180 | iter.when = eventp->present + delay; |
| 181 | node = (TIMER_NODE*) acl_avl_find(&eventp->timers->avl, &iter, NULL); |
| 182 | if (node == NULL) { |
| 183 | node = (TIMER_NODE*) acl_mycalloc(1, sizeof(TIMER_NODE)); |
| 184 | node->when = iter.when; |
| 185 | /** |
| 186 | * Insert the request at the right place. Timer requests are |
| 187 | * kept sorted to reduce lookup overhead in the event loop. |
| 188 | */ |
| 189 | acl_avl_add(&eventp->timers->avl, node); |
| 190 | } |
| 191 | |
| 192 | node_link(node, info); |
| 193 | return node->when; |
| 194 | } |
| 195 | |
| 196 | /* event_timer_cancel - cancel timer */ |
| 197 |
no test coverage detected
searching dependent graphs…