mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-23 15:00:02 +02:00
48 lines
1023 B
C++
Executable File
48 lines
1023 B
C++
Executable File
#pragma once
|
|
/************************************************
|
|
* @file ThreadObject.h
|
|
* @short creates/destroys a thread
|
|
***********************************************/
|
|
/**
|
|
*@short creates/destroys a thread
|
|
*/
|
|
|
|
#include "sls_detector_defs.h"
|
|
#include "logger.h"
|
|
|
|
|
|
#include <semaphore.h>
|
|
#include <string>
|
|
#include <atomic>
|
|
#include <future>
|
|
|
|
class ThreadObject : private virtual slsDetectorDefs {
|
|
|
|
public:
|
|
ThreadObject(int threadIndex, std::string threadType);
|
|
virtual ~ThreadObject();
|
|
virtual bool IsRunning() = 0;
|
|
void Continue();
|
|
void SetThreadPriority(int priority);
|
|
|
|
protected:
|
|
virtual void ThreadExecution() = 0;
|
|
|
|
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();
|
|
|
|
|
|
protected:
|
|
int index{0};
|
|
std::string type;
|
|
std::atomic<bool> killThread{false};
|
|
std::unique_ptr<std::thread> threadObject;
|
|
sem_t semaphore;
|
|
};
|
|
|