format receiver

This commit is contained in:
Erik Frojdh
2020-05-05 10:04:52 +02:00
parent 3618f6e5d3
commit e599bb7c24
35 changed files with 4642 additions and 4530 deletions

84
slsReceiverSoftware/src/ThreadObject.cpp Executable file → Normal file
View 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, &param) == 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,
&param) == EPERM) {
if (index == 0) {
LOG(logWARNING) << "Could not prioritize " << type
<< " thread. "
"(No Root Privileges?)";
}
} else {
LOG(logINFO) << "Priorities set - " << type << ": " << priority;
}
}