Dhanya Thattil f5160b0978
exposing receiver thread ids to client (#102)
* exposing receiver thread ids to client

Co-authored-by: Erik Frojdh <erik.frojdh@gmail.com>
2020-06-09 16:18:37 +02:00

49 lines
1.2 KiB
C++

#pragma once
/************************************************
* @file ThreadObject.h
* @short creates/destroys a thread
***********************************************/
/**
*@short creates/destroys a thread
*/
#include "logger.h"
#include "sls_detector_defs.h"
#include <atomic>
#include <semaphore.h>
#include <string>
#include <thread>
class ThreadObject : private virtual slsDetectorDefs {
protected:
const int index{0};
private:
std::atomic<bool> killThread{false};
std::atomic<bool> runningFlag{false};
std::thread threadObject;
sem_t semaphore;
const std::string type;
pid_t threadId{0};
public:
ThreadObject(int threadIndex, std::string threadType);
virtual ~ThreadObject();
pid_t GetThreadId() const;
bool IsRunning() const;
void StartRunning();
void StopRunning();
void Continue();
void SetThreadPriority(int priority);
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();
};