Cancel a delayed task if running, wait if non_block==false; return immediately if non_block==true
| 106 | /// if running, wait if non_block==false; return immediately if |
| 107 | /// non_block==true |
| 108 | bool CancelTask(int64_t task_id, bool non_block = false, bool* is_running = NULL) { |
| 109 | if (task_id == 0) { |
| 110 | if (is_running != NULL) { |
| 111 | *is_running = false; |
| 112 | } |
| 113 | return false; |
| 114 | } |
| 115 | while (1) { |
| 116 | { |
| 117 | MutexLock lock(&mutex_); |
| 118 | if (running_task_ids_.find(task_id) == running_task_ids_.end()) { |
| 119 | BGMap::iterator it = latest_.find(task_id); |
| 120 | if (it == latest_.end()) { |
| 121 | if (is_running != NULL) { |
| 122 | *is_running = false; |
| 123 | } |
| 124 | return false; |
| 125 | } |
| 126 | latest_.erase(it); |
| 127 | return true; |
| 128 | } else if (non_block) { |
| 129 | if (is_running != NULL) { |
| 130 | *is_running = true; |
| 131 | } |
| 132 | return false; |
| 133 | } |
| 134 | } |
| 135 | timespec ts = {0, 100000}; |
| 136 | nanosleep(&ts, &ts); |
| 137 | } |
| 138 | } |
| 139 | int64_t PendingNum() const { return pending_num_; } |
| 140 | |
| 141 | // log format: 3 numbers seperated by " ", e.g. "15 24 32" |
no outgoing calls
no test coverage detected