Remove a timer from the heap and list of timers.
| 259 | |
| 260 | // Remove a timer from the heap and list of timers. |
| 261 | void remove_timer(per_timer_data& timer) |
| 262 | { |
| 263 | // Remove the timer from the heap. |
| 264 | std::size_t index = timer.heap_index_; |
| 265 | if (!heap_.empty() && index < heap_.size()) |
| 266 | { |
| 267 | if (index == heap_.size() - 1) |
| 268 | { |
| 269 | timer.heap_index_ = (std::numeric_limits<std::size_t>::max)(); |
| 270 | heap_.pop_back(); |
| 271 | } |
| 272 | else |
| 273 | { |
| 274 | swap_heap(index, heap_.size() - 1); |
| 275 | timer.heap_index_ = (std::numeric_limits<std::size_t>::max)(); |
| 276 | heap_.pop_back(); |
| 277 | if (index > 0 && Time_Traits::less_than( |
| 278 | heap_[index].time_, heap_[(index - 1) / 2].time_)) |
| 279 | up_heap(index); |
| 280 | else |
| 281 | down_heap(index); |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | // Remove the timer from the linked list of active timers. |
| 286 | if (timers_ == &timer) |
| 287 | timers_ = timer.next_; |
| 288 | if (timer.prev_) |
| 289 | timer.prev_->next_ = timer.next_; |
| 290 | if (timer.next_) |
| 291 | timer.next_->prev_= timer.prev_; |
| 292 | timer.next_ = 0; |
| 293 | timer.prev_ = 0; |
| 294 | } |
| 295 | |
| 296 | // Determine if the specified absolute time is positive infinity. |
| 297 | template <typename Time_Type> |