| 96 | } |
| 97 | |
| 98 | void |
| 99 | AsyncTimer::cancel() |
| 100 | { |
| 101 | // Assume this object is locked and the state isn't being updated elsewhere. |
| 102 | // Note that is not the same as the contained continuation being locked. |
| 103 | TSCont contp{state_->cont_}; // save this |
| 104 | if (!contp) { |
| 105 | LOG_DEBUG("Already canceled"); |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | auto mutex{TSContMutexGet(contp)}; |
| 110 | TSMutexLock(mutex); // prevent event dispatch for the continuation during this cancel. |
| 111 | |
| 112 | if (state_->initial_timer_action_) { |
| 113 | LOG_DEBUG("Canceling initial timer action"); |
| 114 | TSActionCancel(state_->initial_timer_action_); |
| 115 | } |
| 116 | if (state_->periodic_timer_action_) { |
| 117 | LOG_DEBUG("Canceling periodic timer action"); |
| 118 | TSActionCancel(state_->periodic_timer_action_); |
| 119 | } |
| 120 | state_->cont_ = nullptr; |
| 121 | |
| 122 | TSMutexUnlock(mutex); |
| 123 | |
| 124 | LOG_DEBUG("Destroying cont"); |
| 125 | TSContDestroy(contp); |
| 126 | } |
| 127 | |
| 128 | AsyncTimer::~AsyncTimer() |
| 129 | { |
no test coverage detected