mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-08-10 23:30:30 +02:00
backported binary semaphore for C++20 used in ThreadObject
This commit is contained in:
@@ -16,7 +16,6 @@ namespace sls {
|
||||
ThreadObject::ThreadObject(int index, std::string type)
|
||||
: index(index), type(type) {
|
||||
LOG(logDEBUG) << type << " thread created: " << index;
|
||||
sem_init(&semaphore, 1, 0);
|
||||
try {
|
||||
threadObject = std::thread(&ThreadObject::RunningThread, this);
|
||||
} catch (...) {
|
||||
@@ -27,9 +26,8 @@ ThreadObject::ThreadObject(int index, std::string type)
|
||||
|
||||
ThreadObject::~ThreadObject() {
|
||||
killThread = true;
|
||||
sem_post(&semaphore);
|
||||
semaphore.release();
|
||||
threadObject.join();
|
||||
sem_destroy(&semaphore);
|
||||
}
|
||||
|
||||
pid_t ThreadObject::GetThreadId() const { return threadId; }
|
||||
@@ -49,14 +47,14 @@ void ThreadObject::RunningThread() {
|
||||
ThreadExecution();
|
||||
}
|
||||
// wait till the next acquisition
|
||||
sem_wait(&semaphore);
|
||||
semaphore.acquire();
|
||||
}
|
||||
LOG(logINFOBLUE) << "Exiting [ " << type << " Thread " << index
|
||||
<< ", Tid: " << threadId << "]";
|
||||
threadId = 0;
|
||||
}
|
||||
|
||||
void ThreadObject::Continue() { sem_post(&semaphore); }
|
||||
void ThreadObject::Continue() { semaphore.release(); }
|
||||
|
||||
void ThreadObject::SetThreadPriority(int priority) {
|
||||
struct sched_param param;
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
|
||||
#include "sls/logger.h"
|
||||
#include "sls/sls_detector_defs.h"
|
||||
#include "sls/thread_utils.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <semaphore.h>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
@@ -45,7 +45,7 @@ class ThreadObject : private virtual slsDetectorDefs {
|
||||
std::atomic<bool> killThread{false};
|
||||
std::atomic<bool> runningFlag{false};
|
||||
std::thread threadObject;
|
||||
sem_t semaphore;
|
||||
binary_semaphore semaphore{0};
|
||||
const std::string type;
|
||||
std::atomic<pid_t> threadId{0};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user