Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a lock for m_ContextIDs and m_ContextPtrs #958

Merged
merged 1 commit into from May 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/autonet/AutoNetServerImpl.cpp
Expand Up @@ -322,6 +322,7 @@ void AutoNetServerImpl::HandleUnsubscribe(websocketpp::connection_hdl hdl) {
int AutoNetServerImpl::ResolveContextID(CoreContext* ctxt) {
static int counter = 0;

std::lock_guard<autowiring::spin_lock> lk(m_lock);
if(m_ContextIDs.find(ctxt) == m_ContextIDs.end()){
m_ContextIDs[ctxt] = counter;
m_ContextPtrs[counter] = ctxt;
Expand All @@ -333,6 +334,7 @@ int AutoNetServerImpl::ResolveContextID(CoreContext* ctxt) {
}

CoreContext* AutoNetServerImpl::ResolveContextID(int id) {
std::lock_guard<autowiring::spin_lock> lk(m_lock);
return m_ContextPtrs.at(id);
}

Expand Down
3 changes: 2 additions & 1 deletion src/autonet/AutoNetServerImpl.hpp
Expand Up @@ -135,7 +135,8 @@ class AutoNetServerImpl:
// Set of all subscribers
std::set<AutoNetTransportHandler::connection_hdl, std::owner_less<AutoNetTransportHandler::connection_hdl>> m_Subscribers;

// one-to-one map of contexts to integers
// one-to-one map of contexts to integers, and a lock because we use this in an unsynchronized setting
autowiring::spin_lock m_lock;
std::map<CoreContext*, int> m_ContextIDs;
std::map<int, CoreContext*> m_ContextPtrs;

Expand Down