| 138 | } |
| 139 | |
| 140 | SdkTask* SdkTimeoutManager::PopTask(int64_t task_id) { |
| 141 | uint32_t shard_id = Shard(task_id); |
| 142 | TaskMap& map = map_shard_[shard_id]; |
| 143 | Mutex& mutex = mutex_shard_[shard_id]; |
| 144 | |
| 145 | MutexLock l(&mutex); |
| 146 | IdHashMap::iterator it = map.id_hash_map.find(task_id); |
| 147 | if (it != map.id_hash_map.end()) { |
| 148 | SdkTask* task = it->second; |
| 149 | CHECK_EQ(task->GetId(), task_id); |
| 150 | map.id_hash_map.erase(it); |
| 151 | // make sure that we only erased the right one element |
| 152 | assert(map.due_time_map.erase(task) == 1); |
| 153 | return task; |
| 154 | } else { |
| 155 | return NULL; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | void SdkTimeoutManager::CheckTimeout() { |
| 160 | int64_t now_ms = get_millis(); |