Skip to content

Commit

Permalink
[Core] Fix: proper destructors / rule of 5 for everything involving s…
Browse files Browse the repository at this point in the history
…td::thread (#1334)
  • Loading branch information
KerstinKeller authored and FlorianReimold committed Jan 26, 2024
1 parent c0d3b8f commit d528d42
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
5 changes: 4 additions & 1 deletion ecal/core/include/ecal/ecal_timed_cb.h
Expand Up @@ -97,7 +97,10 @@ namespace eCAL
{
if (!m_running) return(false);
m_stop = true;
m_thread.join();
// Wait for the callback thread to finish
if (m_thread.joinable()) {
m_thread.join();
}
m_running = false;
return(true);
}
Expand Down
5 changes: 5 additions & 0 deletions ecal/core/src/ecal_thread.h
Expand Up @@ -37,6 +37,11 @@ namespace eCAL
CThread();
virtual ~CThread();

CThread(const CThread&) = delete;
CThread& operator=(const CThread&) = delete;
CThread(CThread&& rhs) = delete;
CThread& operator=(CThread&& rhs) = delete;

int Start(int period, std::function<int()> ext_caller_);
int Stop();
int Fire();
Expand Down
4 changes: 4 additions & 0 deletions ecal/core/src/ecal_timer.cpp
Expand Up @@ -38,6 +38,10 @@ namespace eCAL
CTimerImpl(const int timeout_, TimerCallbackT callback_, const int delay_) : m_stop(false), m_running(false) { Start(timeout_, callback_, delay_); }

virtual ~CTimerImpl() { Stop(); }
CTimerImpl(const CTimerImpl&) = delete;
CTimerImpl& operator=(const CTimerImpl&) = delete;
CTimerImpl(CTimerImpl&& rhs) = delete;
CTimerImpl& operator=(CTimerImpl&& rhs) = delete;

bool Start(const int timeout_, TimerCallbackT callback_, const int delay_)
{
Expand Down
5 changes: 4 additions & 1 deletion ecal/core/src/io/ecal_memfile_pool.cpp
Expand Up @@ -309,7 +309,10 @@ namespace eCAL
{
}

CMemFileThreadPool::~CMemFileThreadPool() = default;
CMemFileThreadPool::~CMemFileThreadPool()
{
Destroy();
}

void CMemFileThreadPool::Create()
{
Expand Down
5 changes: 5 additions & 0 deletions ecal/core/src/io/ecal_memfile_pool.h
Expand Up @@ -50,6 +50,11 @@ namespace eCAL
CMemFileObserver();
~CMemFileObserver();

CMemFileObserver(const CMemFileObserver&) = delete;
CMemFileObserver& operator=(const CMemFileObserver&) = delete;
CMemFileObserver(CMemFileObserver&& rhs) = delete;
CMemFileObserver& operator=(CMemFileObserver&& rhs) = delete;

bool Create(const std::string& memfile_name_, const std::string& memfile_event_);
bool Destroy();

Expand Down

0 comments on commit d528d42

Please sign in to comment.