ftpiiu_plugin/src/utils/BackgroundThreadWrapper.hpp

30 lines
589 B
C++
Raw Normal View History

2019-11-24 14:20:08 +01:00
#pragma once
#include "CThread.h"
#include <wut_types.h>
#include <mutex>
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 {
2019-11-24 14:20:08 +01:00
return (exitThread == 1);
}
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
std::recursive_mutex mutex;
2019-11-24 14:20:08 +01:00
private:
2020-11-26 23:32:44 +01:00
void executeThread() override;
2019-11-24 14:20:08 +01:00
virtual BOOL whileLoop() = 0;
volatile int32_t exitThread = 0;
};