Skip to content

Commit

Permalink
remote.h: protect flags access using mutex in stop functions
Browse files Browse the repository at this point in the history
- to make sure that flags accessed in the PassRPC and trans_waiter
classes' stop functions are protected against race conditions, a mutex
based lock is used.

Signed-off-by: Mahmoud Kamel <[email protected]>
  • Loading branch information
Mahmoud Kamel committed Jan 7, 2025
1 parent 6008fb8 commit 32392ec
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions systemc-components/common/include/remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ class PassRPC : public sc_core::sc_module, public transaction_forwarder_if<PASS>
std::condition_variable is_sc_status_set;
std::mutex client_conncted_mut;
std::mutex sc_status_mut;
std::mutex stop_mutex;
std::atomic_bool cancel_waiting;
std::thread::id sc_tid;
std::queue<std::pair<int, bool>> sig_queue;
Expand Down Expand Up @@ -366,6 +367,7 @@ class PassRPC : public sc_core::sc_module, public transaction_forwarder_if<PASS>
std::vector<sc_core::sc_event> port_available_events;
std::vector<bool> is_port_busy;
std::condition_variable is_rpc_execed;
std::mutex start_stop_mutex;
std::mutex rpc_execed_mut;
/**
* FIXME: this is a temp solution for making the b_transport reentrant.
Expand Down Expand Up @@ -400,18 +402,22 @@ class PassRPC : public sc_core::sc_module, public transaction_forwarder_if<PASS>
}
void start()
{
if (is_started) return;

is_started = true;
{
std::lock_guard<std::mutex> start_lg(start_stop_mutex);
if (is_started) return;
is_started = true;
}

notifier_thread = std::thread(&trans_waiter::notifier_task, this);
}

void stop()
{
if (is_stopped || !is_started) return;

is_stopped = true;
{
std::lock_guard<std::mutex> stop_lg(start_stop_mutex);
if (is_stopped || !is_started) return;
is_stopped = true;
}
{
std::lock_guard<std::mutex> lg(rpc_execed_mut);
is_rpc_execed.notify_one();
Expand Down Expand Up @@ -1112,8 +1118,11 @@ class PassRPC : public sc_core::sc_module, public transaction_forwarder_if<PASS>

void stop()
{
if (cancel_waiting || is_local_mode()) return;
cancel_waiting = true;
{
std::lock_guard<std::mutex> lg(stop_mutex);
if (cancel_waiting || is_local_mode()) return;
cancel_waiting = true;
}
{
std::lock_guard<std::mutex> cc_lg(client_conncted_mut);
is_client_connected.notify_one();
Expand Down

0 comments on commit 32392ec

Please sign in to comment.