Skip to content

Commit

Permalink
[Offload][NFC] Make sure the thread is not running already
Browse files Browse the repository at this point in the history
  • Loading branch information
jhuber6 committed Jan 27, 2025
1 parent d7e561b commit e7592d8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion offload/plugins-nextgen/common/include/RPC.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct RPCServerTy {
/// Initialize the worker thread to run in the background.
ServerThread(void *Buffers[], plugin::GenericDeviceTy *Devices[],
size_t Length)
: Running(true), NumUsers(0), CV(), Mutex(), Buffers(Buffers, Length),
: Running(false), NumUsers(0), CV(), Mutex(), Buffers(Buffers, Length),
Devices(Devices, Length) {}

~ServerThread() { assert(!Running && "Thread not shut down explicitly\n"); }
Expand Down
5 changes: 5 additions & 0 deletions offload/plugins-nextgen/common/src/RPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,15 @@ static rpc::Status runServer(plugin::GenericDeviceTy &Device, void *Buffer) {
}

void RPCServerTy::ServerThread::startThread() {
assert(!Running.load(std::memory_order_relaxed) &&
"Attempting to start thread that is already running");
Running.store(true, std::memory_order_release);
Worker = std::thread([this]() { run(); });
}

void RPCServerTy::ServerThread::shutDown() {
assert(Running.load(std::memory_order_relaxed) &&
"Attempting to shut down a thread that is not running");
{
std::lock_guard<decltype(Mutex)> Lock(Mutex);
Running.store(false, std::memory_order_release);
Expand Down

0 comments on commit e7592d8

Please sign in to comment.