| 65 | |
| 66 | |
| 67 | int uv_timer_start(uv_timer_t* handle, |
| 68 | uv_timer_cb cb, |
| 69 | uint64_t timeout, |
| 70 | uint64_t repeat) { |
| 71 | uint64_t clamped_timeout; |
| 72 | |
| 73 | if (uv__is_closing(handle) || cb == NULL) |
| 74 | return UV_EINVAL; |
| 75 | |
| 76 | if (uv__is_active(handle)) |
| 77 | uv_timer_stop(handle); |
| 78 | |
| 79 | clamped_timeout = handle->loop->time + timeout; |
| 80 | if (clamped_timeout < timeout) |
| 81 | clamped_timeout = (uint64_t) -1; |
| 82 | |
| 83 | handle->timer_cb = cb; |
| 84 | handle->timeout = clamped_timeout; |
| 85 | handle->repeat = repeat; |
| 86 | /* start_id is the second index to be compared in timer_less_than() */ |
| 87 | handle->start_id = handle->loop->timer_counter++; |
| 88 | |
| 89 | heap_insert(timer_heap(handle->loop), |
| 90 | (struct heap_node*) &handle->heap_node, |
| 91 | timer_less_than); |
| 92 | uv__handle_start(handle); |
| 93 | |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | |
| 98 | int uv_timer_stop(uv_timer_t* handle) { |
searching dependent graphs…