mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-01 15:26:59 +00:00
25 lines
509 B
C++
25 lines
509 B
C++
#pragma once
|
|
|
|
#include <thread>
|
|
|
|
// pure virtual class to be inherited from by classes which intend to be threaded
|
|
class IThreaded {
|
|
public:
|
|
IThreaded()
|
|
// invokes operator() on this object
|
|
: mThread() { }
|
|
virtual ~IThreaded() noexcept {
|
|
if (mThread.joinable()) {
|
|
mThread.join();
|
|
}
|
|
}
|
|
|
|
virtual void Start() final {
|
|
mThread = std::thread([this] { (*this)(); });
|
|
}
|
|
virtual void operator()() = 0;
|
|
|
|
protected:
|
|
std::thread mThread;
|
|
};
|