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

[Core] Fix: proper destructors / rule of 5 for everything involving std::thread #1334

Merged
merged 2 commits into from Jan 24, 2024
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
14 changes: 9 additions & 5 deletions ecal/core/include/ecal/ecal_timed_cb.h
Expand Up @@ -68,6 +68,11 @@ namespace eCAL
**/
virtual ~CTimedCB() { Stop(); }

CTimedCB(const CTimedCB&) = delete;
CTimedCB& operator=(const CTimedCB&) = delete;
CTimedCB(CTimedCB&& rhs) = delete;
CTimedCB& operator=(CTimedCB&& rhs) = delete;
Comment on lines +71 to +74
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this cause an ABI break? 🤔


/**
* @brief Start the timer.
*
Expand Down Expand Up @@ -97,16 +102,15 @@ 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);
}

private:
// this object must not be copied.
CTimedCB(const CTimedCB&);
CTimedCB& operator=(const CTimedCB&);

void Thread(TimerCallbackT callback_, int timeout_, int delay_)
{
assert(callback_ != nullptr);
Expand Down
5 changes: 4 additions & 1 deletion ecal/core/src/io/shm/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/shm/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
4 changes: 4 additions & 0 deletions ecal/core/src/time/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
10 changes: 10 additions & 0 deletions ecal/core/src/util/ecal_thread.h
Expand Up @@ -44,6 +44,16 @@ namespace eCAL
CCallbackThread(std::function<void()> callback)
: callback_(callback) {}

~CCallbackThread()
{
stop();
}

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

/**
* @brief Start the callback thread with a specified timeout.
* @param timeout The timeout duration for waiting in the callback thread.
Expand Down