38 lines
1.1 KiB
C++
38 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include "ddkit/base/Thread.hpp"
|
|
|
|
namespace ddkit {
|
|
namespace base {
|
|
|
|
/// @brief ThreadSync may be used instead of Thread, if 'start()' shall be 'synchronous', that is
|
|
/// - the os-thread, which is calling 'start()' on this obj, is blocked until
|
|
/// - the new os-thread is created and the intern-thread-function was started
|
|
/// - the overridden 'run()'-method (Derivee from ThreadSync) is started
|
|
/// - the implementation of that 'run'-method decided to call 'ready()'
|
|
/// - (as first command, or after some initialization-steps, which went for some reason not in ctor, but run)
|
|
class ThreadSync : public Thread {
|
|
|
|
public:
|
|
ThreadSync(const std::string& name);
|
|
virtual ~ThreadSync() override;
|
|
|
|
protected:
|
|
void ready();
|
|
|
|
private:
|
|
std::recursive_mutex m_mutex;
|
|
std::condition_variable_any m_condition;
|
|
|
|
bool m_isReady; // did the thread call "ready()" for signaling "fully" starting up?
|
|
|
|
void waitForReadyIf() override; // called by Thread
|
|
|
|
ThreadSync(ThreadSync const&) = delete;
|
|
void operator=(ThreadSync const&) = delete;
|
|
};
|
|
|
|
|
|
} // namespace base
|
|
} // namespace ddkit
|