Skip to content

Commit

Permalink
data race in reader, writer, client, server create/register/unregiste…
Browse files Browse the repository at this point in the history
…r logic
  • Loading branch information
rex-schilasky committed Mar 18, 2024
1 parent 4baac72 commit ab8fa6b
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 19 deletions.
9 changes: 6 additions & 3 deletions ecal/core/src/readwrite/ecal_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ namespace eCAL
// register
Register(false);

// mark as created
// and mark as created
m_created = true;

return(true);
Expand Down Expand Up @@ -155,11 +155,13 @@ namespace eCAL
m_event_callback_map.clear();
}

// unregister
// mark as no more created
m_created = false;

// and unregister
Unregister();

// reset defaults
m_created = false;
m_clock = 0;
m_message_drops = 0;

Expand Down Expand Up @@ -230,6 +232,7 @@ namespace eCAL
bool CDataReader::Register(const bool force_)
{
#if ECAL_CORE_REGISTRATION
if (!m_created) return(false);
if(m_topic_name.empty()) return(false);

// create command parameter
Expand Down
10 changes: 6 additions & 4 deletions ecal/core/src/readwrite/ecal_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ namespace eCAL
// register
Register(false);

// mark as created
// and mark as created
m_created = true;

// create udp multicast layer
Expand Down Expand Up @@ -210,11 +210,12 @@ namespace eCAL
m_event_callback_map.clear();
}

// unregister
Unregister();

// mark as no more created
m_created = false;

// and unregister
Unregister();

return(true);
}

Expand Down Expand Up @@ -771,6 +772,7 @@ namespace eCAL
bool CDataWriter::Register(bool force_)
{
#if ECAL_CORE_REGISTRATION
if (!m_created) return(false);
if (m_topic_name.empty()) return(false);

//@Rex: why is the logic different in CDataReader???
Expand Down
2 changes: 1 addition & 1 deletion ecal/core/src/readwrite/ecal_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,6 @@ namespace eCAL
bool m_use_tdesc;
int m_share_ttype;
int m_share_tdesc;
bool m_created;
std::atomic<bool> m_created;
};
}
11 changes: 6 additions & 5 deletions ecal/core/src/service/ecal_service_client_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace eCAL
// register this client
Register(false);

// mark as created
// and mark as created
m_created = true;

return(true);
Expand Down Expand Up @@ -108,17 +108,17 @@ namespace eCAL
m_event_callback_map.clear();
}

// unregister this client
// mark as no more created
m_created = false;

// and unregister this client
Unregister();

// reset internals
m_service_name.clear();
m_service_id.clear();
m_host_name.clear();

// mark as not created
m_created = false;

return(true);
}

Expand Down Expand Up @@ -616,6 +616,7 @@ namespace eCAL

void CServiceClientImpl::Register(const bool force_)
{
if (!m_created) return;
if (m_service_name.empty()) return;

Registration::Sample sample;
Expand Down
2 changes: 1 addition & 1 deletion ecal/core/src/service/ecal_service_client_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,6 @@ namespace eCAL
std::string m_service_id;
std::string m_host_name;

bool m_created;
std::atomic<bool> m_created;
};
}
10 changes: 6 additions & 4 deletions ecal/core/src/service/ecal_service_server_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ namespace eCAL
// register this service
Register(false);

// mark as created
// and mark as created
m_created = true;

return(true);
Expand Down Expand Up @@ -176,7 +176,10 @@ namespace eCAL
m_event_callback_map.clear();
}

// unregister this service
// mark as no more created
m_created = false;

// and unregister this service
Unregister();

// reset internals
Expand All @@ -189,8 +192,6 @@ namespace eCAL
m_connected_v1 = false;
}

m_created = false;

return(true);
}

Expand Down Expand Up @@ -342,6 +343,7 @@ namespace eCAL

void CServiceServerImpl::Register(const bool force_)
{
if (!m_created) return;
if (m_service_name.empty()) return;

// might be zero in contruction phase
Expand Down
2 changes: 1 addition & 1 deletion ecal/core/src/service/ecal_service_server_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace eCAL
std::mutex m_event_callback_map_sync;
EventCallbackMapT m_event_callback_map;

bool m_created = false;
std::atomic<bool> m_created = false;

mutable std::mutex m_connected_mutex; //!< mutex protecting the m_connected_v0 and m_connected_v1 variable, as those are modified by the event callbacks in another thread.
bool m_connected_v0 = false;
Expand Down

0 comments on commit ab8fa6b

Please sign in to comment.