Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions SilKit/source/core/vasio/ConnectKnownParticipants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ void ConnectKnownParticipants::UpdateStage()
{
SILKIT_TRACE_METHOD_(_logger, "()");

// Serialize the whole transition: _connectStage is atomic, but the check-then-set below is not,
// so concurrent callers would otherwise fire the same stage callback (e.g. set_value()) twice.
std::lock_guard<decltype(_stageMutex)> stageLock{_stageMutex};

if (_connectStage == ConnectStage::INVALID)
{
return;
Expand Down
4 changes: 4 additions & 0 deletions SilKit/source/core/vasio/ConnectKnownParticipants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ class ConnectKnownParticipants

std::atomic<ConnectStage> _connectStage{ConnectStage::INVALID};

// Serializes the check-then-set stage transitions in UpdateStage(), which can be called
// concurrently from the caller thread (StartConnecting) and the IO worker thread (connect callbacks).
std::mutex _stageMutex{};

mutable std::mutex _mutex{};
std::unordered_map<std::string, std::unique_ptr<Peer>> _peers;

Expand Down
Loading