diff --git a/src/bm_sim/switch.cpp b/src/bm_sim/switch.cpp index e360c5cea..5110a4d0d 100644 --- a/src/bm_sim/switch.cpp +++ b/src/bm_sim/switch.cpp @@ -75,14 +75,14 @@ SwitchWContexts::receive(port_t port_num, const char *buffer, int len) { void SwitchWContexts::start_and_return() { - { - std::unique_lock config_lock(config_mutex); - if (!config_loaded && !enable_swap) { - Logger::get()->error( - "The switch was started with no P4 and config swap is disabled"); - } - config_loaded_cv.wait(config_lock, [this]() { return config_loaded; }); + std::unique_lock config_lock(config_mutex); + if (!config_loaded && !enable_swap) { + Logger::get()->error( + "The switch was started with no P4 and config swap is disabled"); } + // We keep holding the lock as the start_and_return_ callback, which is + // implemented by targets, may access the P4 config for some validations. + config_loaded_cv.wait(config_lock, [this]() { return config_loaded; }); start(); // DevMgr::start start_and_return_(); // Starts any registered periodically-executing externs