move libthread to libstb-hal

This commit is contained in:
smogm
2015-01-12 18:15:08 +01:00
parent 3ef2eeb8aa
commit 95ee7f9e98
25 changed files with 915 additions and 86 deletions

View File

@@ -18,7 +18,5 @@ libcommon_la_SOURCES = \
endif
libcommon_la_SOURCES += \
thread_abstraction.cpp \
mutex_abstraction.cpp \
lt_debug.cpp \
proc_tools.c

View File

@@ -1,22 +0,0 @@
#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

@@ -1,20 +0,0 @@
#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

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

@@ -1,25 +0,0 @@
#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