From 9979ce251df26e39734e5a225be7febdea36073c Mon Sep 17 00:00:00 2001 From: Matthew Lam Date: Thu, 23 May 2024 13:06:45 -0700 Subject: [PATCH] Fix race condition when accessing source info in action primitives (#1251) Fixes #1250 --- include/bm/bm_sim/actions.h | 2 +- src/bm_sim/actions.cpp | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/include/bm/bm_sim/actions.h b/include/bm/bm_sim/actions.h index bb99ac11c..b0ef3787e 100644 --- a/include/bm/bm_sim/actions.h +++ b/include/bm/bm_sim/actions.h @@ -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; diff --git a/src/bm_sim/actions.cpp b/src/bm_sim/actions.cpp index 24b76cca3..7fb8c3ec5 100644 --- a/src/bm_sim/actions.cpp +++ b/src/bm_sim/actions.cpp @@ -20,13 +20,29 @@ */ #include +#include #include +#include #include +#include +#include +#include #include #include -#include - +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include #include +#include #include #include "utils.h" @@ -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 {