| 258 | } |
| 259 | |
| 260 | void BatchHelper::DispatchBatchTask(int vtid) { |
| 261 | auto &batch_infos = impl_->vtid2batch_infos[vtid]; |
| 262 | auto rwlock = &impl_->vtid2rwlock[vtid]; |
| 263 | auto &idle_process_ctxs = impl_->vtid2idle_process_ctxs[vtid]; |
| 264 | |
| 265 | static __thread uint64_t next_dispatch_timestampe_ms = 0; |
| 266 | uint64_t ready_timestamp_ms; |
| 267 | |
| 268 | if (next_dispatch_timestampe_ms && next_dispatch_timestampe_ms > comm::utils::Time::GetSteadyClockMS()) return; |
| 269 | next_dispatch_timestampe_ms = 0; |
| 270 | |
| 271 | comm::utils::RWLock rwlock_read(rwlock, comm::utils::RWLock::LockMode::READ); |
| 272 | |
| 273 | for (auto &&kv : batch_infos) { |
| 274 | auto batch_info = &kv.second; |
| 275 | |
| 276 | lock_guard<mutex> lock_guard(batch_info->first); |
| 277 | auto &batch_task = batch_info->second; |
| 278 | |
| 279 | if (nullptr != batch_task) { |
| 280 | if (batch_task->Ready(&ready_timestamp_ms)) { |
| 281 | if (!idle_process_ctxs.empty()) { |
| 282 | auto ctx = idle_process_ctxs.top(); |
| 283 | idle_process_ctxs.pop(); |
| 284 | ctx->ready_batch_task = move(batch_task); |
| 285 | co_resume(ctx->co); |
| 286 | } |
| 287 | } else { |
| 288 | if (ready_timestamp_ms > 0 && (0 == next_dispatch_timestampe_ms || ready_timestamp_ms < next_dispatch_timestampe_ms)) { |
| 289 | next_dispatch_timestampe_ms = ready_timestamp_ms; |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | static void *ProcessRoutineRun(void *arg) { |
| 297 | co_enable_hook_sys(); |
no test coverage detected