Skip to content

Commit

Permalink
Fix race condition in start_and_return (#1244)
Browse files Browse the repository at this point in the history
Fix race conditions when passing a BMv2 JSON Config into the command-line arguments when initializing SimpleSwitch.

Fixes #1243
  • Loading branch information
matthewtlam authored Apr 17, 2024
1 parent 2ad84a2 commit c37ec2d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/bm_sim/switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ SwitchWContexts::receive(port_t port_num, const char *buffer, int len) {

void
SwitchWContexts::start_and_return() {
{
std::unique_lock<std::mutex> 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<std::mutex> 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
Expand Down

0 comments on commit c37ec2d

Please sign in to comment.