ftpiiu_plugin/src/utils/BackgroundThreadWrapper.hpp

38 lines
716 B
C++
Raw Normal View History

2019-11-24 14:20:08 +01:00
#pragma once
#include "CThread.h"
#include <mutex>
2022-02-04 14:33:59 +01:00
#include <wut_types.h>
2019-11-24 14:20:08 +01:00
2021-09-24 19:49:11 +02:00
class BackgroundThreadWrapper : public CThread {
2019-11-24 14:20:08 +01:00
public:
2020-11-26 23:32:44 +01:00
explicit BackgroundThreadWrapper(int32_t priority);
2021-09-24 19:49:11 +02:00
2020-11-26 23:32:44 +01:00
~BackgroundThreadWrapper() override;
2021-09-24 19:49:11 +02:00
2019-11-24 14:20:08 +01:00
protected:
2020-11-26 23:32:44 +01:00
[[nodiscard]] BOOL shouldExit() const {
return (exitThread);
2019-11-24 14:20:08 +01:00
}
2020-11-26 23:32:44 +01:00
void setThreadPriority(int32_t priority) override {
CThread::setThreadPriority(priority);
2019-11-24 14:20:08 +01:00
}
2021-09-24 19:49:11 +02:00
void stopThread() {
exitThread = true;
}
bool hasThreadStopped() {
return threadEnded;
}
2019-11-24 14:20:08 +01:00
private:
volatile bool threadEnded = false;
volatile bool exitThread = false;
2020-11-26 23:32:44 +01:00
void executeThread() override;
2019-11-24 14:20:08 +01:00
virtual BOOL whileLoop() = 0;
};