mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-03 08:15:35 +00:00
use boost::scoped_thread in IThreaded
This commit is contained in:
parent
9502048525
commit
3de142a6d0
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <boost/thread/scoped_thread.hpp>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
// pure virtual class to be inherited from by classes which intend to be threaded
|
// pure virtual class to be inherited from by classes which intend to be threaded
|
||||||
@ -9,16 +10,14 @@ public:
|
|||||||
// invokes operator() on this object
|
// invokes operator() on this object
|
||||||
: mThread() { }
|
: mThread() { }
|
||||||
virtual ~IThreaded() noexcept {
|
virtual ~IThreaded() noexcept {
|
||||||
if (mThread.joinable()) {
|
mThread.interrupt();
|
||||||
mThread.join();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Start() final {
|
virtual void Start() final {
|
||||||
mThread = std::thread([this] { (*this)(); });
|
mThread = boost::scoped_thread<>([this] { (*this)(); });
|
||||||
}
|
}
|
||||||
virtual void operator()() = 0;
|
virtual void operator()() = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::thread mThread;
|
boost::scoped_thread<> mThread {};
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user