mirror of
https://github.com/tuxbox-neutrino/libstb-hal.git
synced 2025-08-27 07:23:11 +02:00
add mutex and thread abstraction to common files
This commit is contained in:
33
common/thread_abstraction.cpp
Normal file
33
common/thread_abstraction.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "thread_abstraction.h"
|
||||
|
||||
Thread::Thread() :
|
||||
mIsRunning(false),
|
||||
mThread()
|
||||
{
|
||||
}
|
||||
|
||||
Thread::~Thread()
|
||||
{
|
||||
// if thread is still running on object destruction, cancel thread the hard way:
|
||||
if (mIsRunning)
|
||||
{
|
||||
pthread_cancel(mThread);
|
||||
}
|
||||
}
|
||||
|
||||
void Thread::startThread()
|
||||
{
|
||||
mIsRunning = true;
|
||||
pthread_create(&mThread, 0, &Thread::runThread, this);
|
||||
}
|
||||
|
||||
void Thread::joinThread()
|
||||
{
|
||||
pthread_join(mThread, 0);
|
||||
mIsRunning = false;
|
||||
}
|
||||
|
||||
void* Thread::runThread(void* ptr)
|
||||
{
|
||||
((Thread*)ptr)->run();
|
||||
}
|
Reference in New Issue
Block a user