lasp/cpp_src/device/lasp_indatahandler.cpp
J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F e973f14884
Some checks failed
Building, testing and releasing LASP if it has a tag / Build-Test-Ubuntu (push) Failing after 2m3s
Building, testing and releasing LASP if it has a tag / Release-Ubuntu (push) Has been skipped
Weak refs to Recording methods. Made the mutexes more simple for stream manager. Added extra guards and statements here and there. Code passes a sever stress test.
2024-03-13 12:19:24 +01:00

62 lines
1.5 KiB
C++

// #define DEBUGTRACE_ENABLED
#include "lasp_indatahandler.h"
#include "debugtrace.hpp"
#include "lasp_streammgr.h"
#include <thread>
InDataHandler::InDataHandler(SmgrHandle mgr, const InCallbackType cb,
const ResetCallbackType resetfcn)
: _mgr(mgr), inCallback(cb), reset(resetfcn)
#if LASP_DEBUG == 1
,
main_thread_id(std::this_thread::get_id())
#endif
{
DEBUGTRACE_ENTER;
#if LASP_DEBUG == 1
assert(mgr->main_thread_id == main_thread_id);
#endif
}
void InDataHandler::start() {
DEBUGTRACE_ENTER;
checkRightThread();
if (SmgrHandle handle = _mgr.lock()) {
handle->addInDataHandler(this);
#if LASP_DEBUG == 1
assert(handle->main_thread_id == main_thread_id);
#endif
}
}
void InDataHandler::stop() {
DEBUGTRACE_ENTER;
// checkRightThread();
#if LASP_DEBUG == 1
stopCalled = true;
#endif
if (SmgrHandle smgr = _mgr.lock()) {
smgr->removeInDataHandler(*this);
} else {
DEBUGTRACE_PRINT("No stream manager alive anymore!");
}
}
InDataHandler::~InDataHandler() {
DEBUGTRACE_ENTER;
#if LASP_DEBUG == 1
// checkRightThread();
if (!stopCalled) {
std::cerr << "************ BUG: Stop function not called while arriving at "
"InDataHandler's destructor. Fix this by calling "
"InDataHandler::stop()."
<< std::endl;
abort();
}
#endif
}
#if LASP_DEBUG == 1
void InDataHandler::checkRightThread() const {
assert(std::this_thread::get_id() == main_thread_id);
}
#endif