mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-libstb-hal.git
synced 2025-08-26 15:02:43 +02:00
Origin commit data
------------------
Branch: master
Commit: 95ee7f9e98
Author: smogm <smogm@vh0st.me>
Date: 2015-01-12 (Mon, 12 Jan 2015)
------------------
No further description and justification available within origin commit message!
------------------
This commit was generated by Migit
59 lines
972 B
C++
59 lines
972 B
C++
#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);
|
|
}
|
|
}
|
|
|
|
int Thread::startThread()
|
|
{
|
|
mIsRunning = true;
|
|
return pthread_create(&mThread, 0, &Thread::runThread, this);
|
|
}
|
|
|
|
int Thread::cancelThread()
|
|
{
|
|
return pthread_cancel(mThread);
|
|
mIsRunning = false;
|
|
}
|
|
|
|
int Thread::detachThread()
|
|
{
|
|
mIsRunning = false; // thread shall not cancel on object destruction!
|
|
return pthread_detach(mThread);
|
|
}
|
|
|
|
int Thread::joinThread()
|
|
{
|
|
int ret = pthread_join(mThread, 0);
|
|
mIsRunning = false;
|
|
return ret;
|
|
}
|
|
|
|
int Thread::setCancelModeDisable()
|
|
{
|
|
return pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, 0);
|
|
}
|
|
|
|
int Thread::setSchedulePriority(int prio)
|
|
{
|
|
return pthread_setschedprio(mThread, prio);
|
|
}
|
|
|
|
void* Thread::runThread(void* ptr)
|
|
{
|
|
Thread* t = static_cast<Thread*>(ptr);
|
|
t->run();
|
|
return 0;
|
|
}
|