Revert "move libthread to libstb-hal"

This reverts commit 95ee7f9e98.
This commit is contained in:
max_10
2018-09-20 17:42:13 +02:00
committed by Thilo Graf
parent 10710b9b53
commit 1aece863c1
23 changed files with 85 additions and 272 deletions

View File

@@ -31,6 +31,8 @@ endif
endif
libcommon_la_SOURCES += \
thread_abstraction.cpp \
mutex_abstraction.cpp \
lt_debug.cpp \
proc_tools.c \
pwrmngr.cpp

View File

@@ -0,0 +1,22 @@
#include "mutex_abstraction.h"
Mutex::Mutex() :
mMutex()
{
pthread_mutex_init(&mMutex, 0);
}
Mutex::~Mutex()
{
pthread_mutex_destroy(&mMutex);
}
void Mutex::lock()
{
pthread_mutex_lock(&mMutex);
}
void Mutex::unlock()
{
pthread_mutex_unlock(&mMutex);
}

View File

@@ -0,0 +1,20 @@
#ifndef _MUTEX_ABSTRACTION_H
#define _MUTEX_ABSTRACTION_H
#include <pthread.h>
class Mutex
{
pthread_mutex_t mMutex;
Mutex(const Mutex&);
const Mutex& operator=(const Mutex&);
public:
Mutex();
virtual ~Mutex();
void lock();
void unlock();
};
#endif

View File

@@ -0,0 +1,34 @@
#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;
}

View File

@@ -0,0 +1,25 @@
#ifndef _SIMPLETHREAD_ABSTRACTION_H
#define _SIMPLETHREAD_ABSTRACTION_H
#include <pthread.h>
class SimpleThread
{
bool mIsRunning;
pthread_t mThread;
static void* runThread(void*);
SimpleThread(const SimpleThread&);
const SimpleThread& operator=(const SimpleThread&);
public:
SimpleThread();
~SimpleThread();
void startThread();
void joinThread();
protected:
virtual void run() = 0;
};
#endif