mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-12-30 16:11:19 +01:00
format receiver
This commit is contained in:
84
slsReceiverSoftware/src/ThreadObject.cpp
Executable file → Normal file
84
slsReceiverSoftware/src/ThreadObject.cpp
Executable file → Normal file
@@ -10,61 +10,57 @@
|
||||
#include <unistd.h>
|
||||
|
||||
ThreadObject::ThreadObject(int threadIndex, std::string threadType)
|
||||
: index(threadIndex), type(threadType) {
|
||||
LOG(logDEBUG) << type << " thread created: " << index;
|
||||
sem_init(&semaphore,1,0);
|
||||
try {
|
||||
threadObject = std::thread(&ThreadObject::RunningThread, this);
|
||||
} catch (...) {
|
||||
throw sls::RuntimeError("Could not create " + type + " thread with index " + std::to_string(index));
|
||||
}
|
||||
: index(threadIndex), type(threadType) {
|
||||
LOG(logDEBUG) << type << " thread created: " << index;
|
||||
sem_init(&semaphore, 1, 0);
|
||||
try {
|
||||
threadObject = std::thread(&ThreadObject::RunningThread, this);
|
||||
} catch (...) {
|
||||
throw sls::RuntimeError("Could not create " + type +
|
||||
" thread with index " + std::to_string(index));
|
||||
}
|
||||
}
|
||||
|
||||
ThreadObject::~ThreadObject() {
|
||||
killThread = true;
|
||||
sem_post(&semaphore);
|
||||
threadObject.join();
|
||||
sem_destroy(&semaphore);
|
||||
killThread = true;
|
||||
sem_post(&semaphore);
|
||||
threadObject.join();
|
||||
sem_destroy(&semaphore);
|
||||
}
|
||||
|
||||
bool ThreadObject::IsRunning() const{
|
||||
return runningFlag;
|
||||
}
|
||||
bool ThreadObject::IsRunning() const { return runningFlag; }
|
||||
|
||||
void ThreadObject::StartRunning() {
|
||||
runningFlag = true;
|
||||
}
|
||||
void ThreadObject::StartRunning() { runningFlag = true; }
|
||||
|
||||
void ThreadObject::StopRunning() {
|
||||
runningFlag = false;
|
||||
}
|
||||
void ThreadObject::StopRunning() { runningFlag = false; }
|
||||
|
||||
void ThreadObject::RunningThread() {
|
||||
LOG(logINFOBLUE) << "Created [ " << type << "Thread " << index << ", Tid: " << syscall(SYS_gettid) << "]";
|
||||
while(!killThread) {
|
||||
while(IsRunning()) {
|
||||
ThreadExecution();
|
||||
}
|
||||
//wait till the next acquisition
|
||||
sem_wait(&semaphore);
|
||||
}
|
||||
LOG(logINFOBLUE) << "Exiting [ " << type << " Thread " << index << ", Tid: " << syscall(SYS_gettid) << "]";
|
||||
LOG(logINFOBLUE) << "Created [ " << type << "Thread " << index
|
||||
<< ", Tid: " << syscall(SYS_gettid) << "]";
|
||||
while (!killThread) {
|
||||
while (IsRunning()) {
|
||||
ThreadExecution();
|
||||
}
|
||||
// wait till the next acquisition
|
||||
sem_wait(&semaphore);
|
||||
}
|
||||
LOG(logINFOBLUE) << "Exiting [ " << type << " Thread " << index
|
||||
<< ", Tid: " << syscall(SYS_gettid) << "]";
|
||||
}
|
||||
|
||||
|
||||
void ThreadObject::Continue() {
|
||||
sem_post(&semaphore);
|
||||
}
|
||||
void ThreadObject::Continue() { sem_post(&semaphore); }
|
||||
|
||||
void ThreadObject::SetThreadPriority(int priority) {
|
||||
struct sched_param param;
|
||||
param.sched_priority = priority;
|
||||
if (pthread_setschedparam(threadObject.native_handle(), SCHED_FIFO, ¶m) == EPERM) {
|
||||
if (index == 0) {
|
||||
LOG(logWARNING) << "Could not prioritize " << type << " thread. "
|
||||
"(No Root Privileges?)";
|
||||
}
|
||||
} else {
|
||||
LOG(logINFO) << "Priorities set - " << type << ": " << priority;
|
||||
}
|
||||
struct sched_param param;
|
||||
param.sched_priority = priority;
|
||||
if (pthread_setschedparam(threadObject.native_handle(), SCHED_FIFO,
|
||||
¶m) == EPERM) {
|
||||
if (index == 0) {
|
||||
LOG(logWARNING) << "Could not prioritize " << type
|
||||
<< " thread. "
|
||||
"(No Root Privileges?)";
|
||||
}
|
||||
} else {
|
||||
LOG(logINFO) << "Priorities set - " << type << ": " << priority;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user