rxr: switched to threads for threadObject (from pthread), moved priorities to threadObject, mutex

This commit is contained in:
2019-11-29 16:19:02 +01:00
parent 16bec25b0c
commit 1a8337540a
11 changed files with 75 additions and 285 deletions

View File

@ -118,12 +118,6 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
*/
void SetGeneralData(GeneralData* g);
/**
* Set thread priority
* @priority priority
*/
void SetThreadPriority(int priority);
/**
* Set File Format
* @param f file format
@ -199,12 +193,6 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
private:
/**
* Get Type
* @return type
*/
std::string GetType() override;
/**
* Record First Index
* @param fnum frame index to record

View File

@ -79,12 +79,6 @@ class DataStreamer : private virtual slsDetectorDefs, public ThreadObject {
*/
void SetGeneralData(GeneralData* g);
/**
* Set thread priority
* @priority priority
*/
void SetThreadPriority(int priority);
/**
* Set number of detectors
* @param number of detectors in both dimensions
@ -119,12 +113,6 @@ class DataStreamer : private virtual slsDetectorDefs, public ThreadObject {
private:
/**
* Get Type
* @return type
*/
std::string GetType();
/**
* Record First Index
* @param fnum frame index to record

View File

@ -17,6 +17,7 @@
#ifndef H5_NO_NAMESPACE
using namespace H5;
#endif
#include <mutex>
class HDF5File : private virtual slsDetectorDefs, public File, public HDF5FileStatic {
@ -130,9 +131,8 @@ class HDF5File : private virtual slsDetectorDefs, public File, public HDF5FileSt
void UpdateDataType();
/** mutex to update static items among objects (threads)*/
static pthread_mutex_t Mutex;
static mutable std::mutex mutex;
/** Master File handle */
static H5File* masterfd;

View File

@ -102,12 +102,6 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
*/
void SetGeneralData(GeneralData* g);
/**
* Set thread priority
* @priority priority
*/
void SetThreadPriority(int priority);
/**
* Creates UDP Sockets
*/
@ -136,12 +130,6 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
private:
/**
* Get Type
* @return type
*/
std::string GetType() override;
/**
* Record First Acquisition Index
* @param fnum frame index to record

View File

@ -10,76 +10,27 @@
#include "sls_detector_defs.h"
#include "logger.h"
#include <pthread.h>
#include <semaphore.h>
#include <string>
#include <atomic>
#include <future>
class ThreadObject : private virtual slsDetectorDefs {
public:
/**
* Constructor
* @param ind self index
*/
ThreadObject(int ind);
/**
* Destructor
* if alive, destroys thread
*/
ThreadObject(int threadIndex, std::string threadType);
virtual ~ThreadObject();
/**
* Print all member values
*/
void PrintMembers();
/**
* Get Type
* @return type
*/
virtual std::string GetType() = 0;
/**
* Returns if the thread is currently running
* @returns true if thread is running, else false
*/
virtual bool IsRunning() = 0;
/**
* What is really being executed in the thread
*/
virtual void ThreadExecution() = 0;
/**
* Post semaphore so thread can continue & start an acquisition
*/
void Continue();
void SetThreadPriority(int priority);
protected:
/**
* Destroy thread, semaphore and resets alive and killThread
*/
void DestroyThread();
/**
* Create Thread, sets semaphore, alive and killThread
*/
void CreateThread();
virtual void ThreadExecution() = 0;
private:
/**
* Static function using pointer from argument to call RunningThread()
* @param thisPointer pointer to an object of ThreadObject
*/
static void* StartThread(void *thisPointer);
/**
* Actual Thread called: An infinite while loop in which,
* 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
*/
@ -87,22 +38,10 @@ class ThreadObject : private virtual slsDetectorDefs {
protected:
/** Self Index */
int index;
/** Thread is alive/dead */
volatile bool alive;
/** Variable monitored by thread to kills itself */
volatile bool killThread;
/** Thread variable */
pthread_t thread;
/** Semaphore to synchonize starting of each run */
int index{0};
std::string type;
std::atomic<bool> killThread{false};
std::unique_ptr<std::thread> threadObject;
sem_t semaphore;
};