Skip to content

Commit

Permalink
Fix race condition when accessing source info in action primitives (#…
Browse files Browse the repository at this point in the history
…1251)

Fixes #1250
  • Loading branch information
matthewtlam authored May 23, 2024
1 parent 8e183a3 commit 9979ce2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/bm/bm_sim/actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ class ActionPrimitive_ {
// (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60056).
static thread_local Packet *pkt;
static thread_local PHV *phv;
SourceInfo *call_source_info{nullptr};
static thread_local SourceInfo *call_source_info;

P4Objects *get_p4objects() {
return p4objects;
Expand Down
21 changes: 19 additions & 2 deletions src/bm_sim/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,29 @@
*/

#include <bm/bm_sim/actions.h>
#include <bm/bm_sim/data.h>
#include <bm/bm_sim/debugger.h>
#include <bm/bm_sim/expressions.h>
#include <bm/bm_sim/event_logger.h>
#include <bm/bm_sim/header_unions.h>
#include <bm/bm_sim/logger.h>
#include <bm/bm_sim/named_p4object.h>
#include <bm/bm_sim/P4Objects.h>
#include <bm/bm_sim/packet.h>
#include <bm/bm_sim/logger.h>

#include <bm/bm_sim/phv.h>
#include <bm/bm_sim/phv_forward.h>
#include <bm/bm_sim/stateful.h>
#include <bm/bm_sim/source_info.h>

#include <cassert>
#include <cstddef>
#include <ios>
#include <iostream>
#include <istream>
#include <memory>
#include <ostream>
#include <string>
#include <utility>
#include <vector>

#include "utils.h"
Expand Down Expand Up @@ -480,6 +496,7 @@ ActionFnEntry::deserialize(std::istream *in, const P4Objects &objs) {

thread_local Packet *ActionPrimitive_::pkt = nullptr;
thread_local PHV *ActionPrimitive_::phv = nullptr;
thread_local SourceInfo *ActionPrimitive_::call_source_info = nullptr;

// TODO(antonin): should this be moved to core/ ?
namespace core {
Expand Down

0 comments on commit 9979ce2

Please sign in to comment.