mirror of
https://github.com/tuxbox-neutrino/libstb-hal.git
synced 2025-08-26 15:02:58 +02:00
35 lines
569 B
C++
35 lines
569 B
C++
#include "thread_abstraction.h"
|
|
|
|
SimpleThread::SimpleThread() :
|
|
mIsRunning(false),
|
|
mThread()
|
|
{
|
|
}
|
|
|
|
SimpleThread::~SimpleThread()
|
|
{
|
|
// if thread is still running on object destruction, cancel thread the hard way:
|
|
if (mIsRunning)
|
|
{
|
|
pthread_cancel(mThread);
|
|
}
|
|
}
|
|
|
|
void SimpleThread::startThread()
|
|
{
|
|
mIsRunning = true;
|
|
pthread_create(&mThread, 0, &SimpleThread::runThread, this);
|
|
}
|
|
|
|
void SimpleThread::joinThread()
|
|
{
|
|
pthread_join(mThread, 0);
|
|
mIsRunning = false;
|
|
}
|
|
|
|
void* SimpleThread::runThread(void* ptr)
|
|
{
|
|
static_cast<SimpleThread*>(ptr)->run();
|
|
return 0;
|
|
}
|