handler for timer event
| 298 | |
| 299 | // handler for timer event |
| 300 | static int |
| 301 | schedule_handler(TSCont contp, TSEvent /*event*/, void * /*data*/) |
| 302 | { |
| 303 | Dbg(ats_wasm::dbg_ctl, "[%s] Inside schedule_handler", __FUNCTION__); |
| 304 | |
| 305 | auto *c = static_cast<ats_wasm::Context *>(TSContDataGet(contp)); |
| 306 | |
| 307 | auto *old_wasm = static_cast<ats_wasm::Wasm *>(c->wasm()); |
| 308 | TSMutexLock(old_wasm->mutex()); |
| 309 | |
| 310 | c->onTick(0); // use 0 as token |
| 311 | |
| 312 | if (wasm_config->configs.empty()) { |
| 313 | TSError("[wasm][%s] Configuration objects are empty", __FUNCTION__); |
| 314 | TSMutexUnlock(old_wasm->mutex()); |
| 315 | return 0; |
| 316 | } |
| 317 | |
| 318 | bool found = false; |
| 319 | for (auto it = wasm_config->configs.begin(); it != wasm_config->configs.end(); it++) { |
| 320 | std::shared_ptr<ats_wasm::Wasm> wbp = it->first; |
| 321 | if (wbp.get() == old_wasm) { |
| 322 | found = true; |
| 323 | auto *wasm = static_cast<ats_wasm::Wasm *>(c->wasm()); |
| 324 | uint32_t root_context_id = c->id(); |
| 325 | if (wasm->existsTimerPeriod(root_context_id)) { |
| 326 | Dbg(ats_wasm::dbg_ctl, "[%s] reschedule continuation", __FUNCTION__); |
| 327 | std::chrono::milliseconds period = wasm->getTimerPeriod(root_context_id); |
| 328 | TSContScheduleOnPool(contp, static_cast<TSHRTime>(period.count()), TS_THREAD_POOL_NET); |
| 329 | } else { |
| 330 | Dbg(ats_wasm::dbg_ctl, "[%s] can't find period for root context id: %d", __FUNCTION__, root_context_id); |
| 331 | } |
| 332 | break; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | if (!found) { |
| 337 | std::shared_ptr<ats_wasm::Wasm> temp = nullptr; |
| 338 | uint32_t root_context_id = c->id(); |
| 339 | old_wasm->removeTimerPeriod(root_context_id); |
| 340 | |
| 341 | if (old_wasm->readyShutdown()) { |
| 342 | Dbg(ats_wasm::dbg_ctl, "[%s] starting WasmBase Shutdown", __FUNCTION__); |
| 343 | old_wasm->startShutdown(); |
| 344 | if (!old_wasm->readyDelete()) { |
| 345 | Dbg(ats_wasm::dbg_ctl, "[%s] not ready to delete WasmBase/PluginBase", __FUNCTION__); |
| 346 | } else { |
| 347 | Dbg(ats_wasm::dbg_ctl, "[%s] remove wasm from deleted_configs", __FUNCTION__); |
| 348 | bool advance = true; |
| 349 | for (auto it = wasm_config->deleted_configs.begin(); it != wasm_config->deleted_configs.end(); advance ? it++ : it) { |
| 350 | advance = true; |
| 351 | Dbg(ats_wasm::dbg_ctl, "[%s] looping through deleted_configs", __FUNCTION__); |
| 352 | std::shared_ptr<ats_wasm::Wasm> wbp = it->first; |
| 353 | temp = wbp; |
| 354 | if (wbp.get() == old_wasm) { |
| 355 | Dbg(ats_wasm::dbg_ctl, "[%s] found matching WasmBase", __FUNCTION__); |
| 356 | it = wasm_config->deleted_configs.erase(it); |
| 357 | advance = false; |
nothing calls this directly
no test coverage detected