backported binary semaphore for C++20 used in ThreadObject
Build on RHEL9 docker image / build (push) Successful in 3m39s
Build on RHEL8 docker image / build (push) Successful in 5m11s
Run Simulator Tests on local RHEL9 / build (push) Successful in 18m15s
Run Simulator Tests on local RHEL8 / build (push) Successful in 21m53s

This commit is contained in:
Erik Fröjdh
2026-05-11 17:10:39 +02:00
parent 50dfba6905
commit d2e8a86ba6
3 changed files with 41 additions and 7 deletions
+3 -5
View File
@@ -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;
+2 -2
View File
@@ -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};
};