mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-13 05:17:13 +02:00
Small refactor on ThreadObject and listener (#93)
* removed pointer, slight cleaning of loop * removed semaphore, use getters * removed redundant log msg * removed comment * added const * removed comment * changed header
This commit is contained in:
@ -7,44 +7,40 @@
|
||||
*@short creates/destroys a thread
|
||||
*/
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
#include "logger.h"
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
#include <semaphore.h>
|
||||
#include <string>
|
||||
#include <atomic>
|
||||
#include <future>
|
||||
|
||||
class ThreadObject : private virtual slsDetectorDefs {
|
||||
|
||||
public:
|
||||
ThreadObject(int threadIndex, std::string threadType);
|
||||
virtual ~ThreadObject();
|
||||
bool IsRunning() const;
|
||||
void StartRunning();
|
||||
void StopRunning();
|
||||
void Continue();
|
||||
void SetThreadPriority(int priority);
|
||||
protected:
|
||||
const int index{0};
|
||||
|
||||
protected:
|
||||
virtual void ThreadExecution() = 0;
|
||||
private:
|
||||
std::atomic<bool> killThread{false};
|
||||
std::atomic<bool> runningFlag{false};
|
||||
std::thread threadObject;
|
||||
sem_t semaphore;
|
||||
const std::string type;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Thread called: An infinite while loop in which,
|
||||
* semaphore starts executing its contents as long RunningMask is satisfied
|
||||
* Then it exits the thread on its own if killThread is true
|
||||
*/
|
||||
void RunningThread();
|
||||
public:
|
||||
ThreadObject(int threadIndex, std::string threadType);
|
||||
virtual ~ThreadObject();
|
||||
bool IsRunning() const;
|
||||
void StartRunning();
|
||||
void StopRunning();
|
||||
void Continue();
|
||||
void SetThreadPriority(int priority);
|
||||
|
||||
|
||||
protected:
|
||||
int index{0};
|
||||
std::string type;
|
||||
std::atomic<bool> killThread{false};
|
||||
std::atomic<bool> runningFlag{false};
|
||||
std::unique_ptr<std::thread> threadObject;
|
||||
sem_t semaphore;
|
||||
private:
|
||||
virtual void ThreadExecution() = 0;
|
||||
/**
|
||||
* Thread called: An infinite while loop in which,
|
||||
* semaphore starts executing its contents as long RunningMask is satisfied
|
||||
* Then it exits the thread on its own if killThread is true
|
||||
*/
|
||||
void RunningThread();
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user