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:
Erik Fröjdh
2020-04-21 09:45:29 +02:00
committed by GitHub
parent 68f76e5356
commit c1ae67ac46
7 changed files with 37 additions and 78 deletions

View File

@ -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();
};