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

creation register unregister data races #45

Merged
merged 13 commits into from
Mar 22, 2024
Merged
7 changes: 2 additions & 5 deletions ecal/core/include/ecal/cimpl/ecal_init_cimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,18 @@
#define eCAL_Init_Monitoring 0x08 /*!< Initialize Monitoring API */
#define eCAL_Init_Logging 0x10 /*!< Initialize Logging API */
#define eCAL_Init_TimeSync 0x20 /*!< Initialize Time API */
#define eCAL_Init_ProcessReg 0x80 /*!< Initialize Process Registration API */

#define eCAL_Init_All (eCAL_Init_Publisher \
| eCAL_Init_Subscriber \
| eCAL_Init_Service \
| eCAL_Init_Monitoring \
| eCAL_Init_Logging \
| eCAL_Init_TimeSync \
| eCAL_Init_ProcessReg) /*!< Initialize complete eCAL API */
| eCAL_Init_TimeSync) /*!< Initialize complete eCAL API */

#define eCAL_Init_Default (eCAL_Init_Publisher \
| eCAL_Init_Subscriber \
| eCAL_Init_Service \
| eCAL_Init_Logging \
| eCAL_Init_TimeSync \
| eCAL_Init_ProcessReg) /*!< Initialize default eCAL API */
| eCAL_Init_TimeSync) /*!< Initialize default eCAL API */

#endif /*ecal_init_cimpl_h_included*/
7 changes: 2 additions & 5 deletions ecal/core/include/ecal/ecal_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,19 @@ namespace eCAL
static const unsigned int Monitoring = 0x008;
static const unsigned int Logging = 0x010;
static const unsigned int TimeSync = 0x020;
static const unsigned int ProcessReg = 0x080;

static const unsigned int All = Publisher
| Subscriber
| Service
| Monitoring
| Logging
| TimeSync
| ProcessReg;
| TimeSync;

static const unsigned int Default = Publisher
| Subscriber
| Service
| Logging
| TimeSync
| ProcessReg;
| TimeSync;

static const unsigned int None = 0x000;
}
Expand Down
2 changes: 1 addition & 1 deletion ecal/core/src/ecal_globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ namespace eCAL
//if (config_instance) config_instance->Create();
if (log_instance && ((components_ & Init::Logging) != 0u)) log_instance->Create();
#if ECAL_CORE_REGISTRATION
if (registration_provider_instance) registration_provider_instance->Create(true, true, (components_ & Init::ProcessReg) != 0x0);
if (registration_provider_instance) registration_provider_instance->Create();
if (registration_receiver_instance) registration_receiver_instance->Create();
#endif
if (descgate_instance) descgate_instance->Create();
Expand Down
13 changes: 8 additions & 5 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 Expand Up @@ -301,7 +304,7 @@ namespace eCAL
ecal_reg_sample_topic.connections_ext = 0;

// register subscriber
if(g_registration_provider() != nullptr) g_registration_provider()->RegisterTopic(m_topic_name, m_topic_id, ecal_reg_sample, force_);
if(g_registration_provider() != nullptr) g_registration_provider()->RegisterSample(ecal_reg_sample, force_);
#ifndef NDEBUG
// log it
Logging::Log(log_level_debug4, m_topic_name + "::CDataReader::DoRegister");
Expand Down Expand Up @@ -329,7 +332,7 @@ namespace eCAL
ecal_reg_sample_topic.uname = Process::GetUnitName();

// unregister subscriber
if (g_registration_provider() != nullptr) g_registration_provider()->UnregisterTopic(m_topic_name, m_topic_id, ecal_unreg_sample, true);
if (g_registration_provider() != nullptr) g_registration_provider()->RegisterSample(ecal_unreg_sample, true);
#ifndef NDEBUG
// log it
Logging::Log(log_level_debug4, m_topic_name + "::CDataReader::Unregister");
Expand Down
1 change: 1 addition & 0 deletions ecal/core/src/readwrite/ecal_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#pragma once

#include <atomic>
#include <chrono>
#include <cstddef>
#include <deque>
Expand Down
14 changes: 8 additions & 6 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 Expand Up @@ -865,7 +867,7 @@ namespace eCAL
ecal_reg_sample_topic.connections_ext = static_cast<int32_t>(ext_connections);

// register publisher
if (g_registration_provider() != nullptr) g_registration_provider()->RegisterTopic(m_topic_name, m_topic_id, ecal_reg_sample, force_);
if (g_registration_provider() != nullptr) g_registration_provider()->RegisterSample(ecal_reg_sample, force_);

#ifndef NDEBUG
// log it
Expand Down Expand Up @@ -895,7 +897,7 @@ namespace eCAL
ecal_reg_sample_topic.uname = Process::GetUnitName();

// unregister publisher
if (g_registration_provider() != nullptr) g_registration_provider()->UnregisterTopic(m_topic_name, m_topic_id, ecal_unreg_sample, true);
if (g_registration_provider() != nullptr) g_registration_provider()->RegisterSample(ecal_unreg_sample, true);

#ifndef NDEBUG
// log it
Expand Down
3 changes: 2 additions & 1 deletion ecal/core/src/readwrite/ecal_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#pragma once

#include <atomic>
#include <chrono>
#include <cstddef>
#include <ecal/ecal_callback.h>
Expand Down Expand Up @@ -217,6 +218,6 @@ namespace eCAL
bool m_use_tdesc;
int m_share_ttype;
int m_share_tdesc;
bool m_created;
std::atomic<bool> m_created;
};
}
Loading
Loading