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

@@ -2,12 +2,11 @@ ACLOCAL_AMFLAGS = -I m4
lib_LTLIBRARIES = libstb-hal.la
libstb_hal_la_SOURCES =
SUBDIRS = common tools libthread
SUBDIRS = common tools
#bin_PROGRAMS = libstb-hal-test
libstb_hal_la_LIBADD = \
common/libcommon.la \
libthread/libthread.la
common/libcommon.la
#libstb_hal_test_SOURCES = libtest.cpp

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

@@ -1,4 +1,4 @@
#include <mutex_abstraction.h>
#include "mutex_abstraction.h"
Mutex::Mutex() :
mMutex()
@@ -6,16 +6,6 @@ Mutex::Mutex() :
pthread_mutex_init(&mMutex, 0);
}
Mutex::Mutex(int attr) :
mMutex()
{
pthread_mutexattr_t Attr;
pthread_mutexattr_init(&Attr);
pthread_mutexattr_settype(&Attr, attr);
pthread_mutex_init(&mMutex, &Attr);
}
Mutex::~Mutex()
{
pthread_mutex_destroy(&mMutex);

View File

@@ -5,21 +5,16 @@
class Mutex
{
friend class Condition;
pthread_mutex_t mMutex;
Mutex(const Mutex&);
const Mutex& operator=(const Mutex&);
protected:
explicit Mutex(int);
public:
Mutex();
virtual ~Mutex();
virtual void lock();
virtual void unlock();
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

View File

@@ -76,7 +76,6 @@ Makefile
common/Makefile
libeplayer3/Makefile
libeplayer3-arm/Makefile
libthread/Makefile
azbox/Makefile
generic-pc/Makefile
libduckbox/Makefile

View File

@@ -104,7 +104,7 @@ int cAudio::Start(void)
{
lt_debug("%s >\n", __func__);
if (! HAL_nodec)
Thread::startThread();
SimpleThread::startThread();
lt_debug("%s <\n", __func__);
return 0;
}
@@ -115,7 +115,7 @@ int cAudio::Stop(void)
if (thread_started)
{
thread_started = false;
Thread::joinThread();
SimpleThread::joinThread();
}
lt_debug("%s <\n", __func__);
return 0;

View File

@@ -4,7 +4,6 @@
#define _AUDIO_LIB_H_
#include <stdint.h>
#include <thread_abstraction.h>
#include "cs_types.h"
typedef enum
@@ -38,7 +37,7 @@ typedef enum
AUDIO_FMT_ADVANCED = AUDIO_FMT_MLP
} AUDIO_FORMAT;
class cAudio : public Thread
class cAudio : public SimpleThread
{
friend class cPlayback;
private:

View File

@@ -64,15 +64,12 @@ static const char *DMX_T[] = {
};
/* map the device numbers. for now only demux0 is used */
#define NUM_DEMUXDEV 1
static const char *devname[NUM_DEMUXDEV] = {
static const char *devname[] = {
"/dev/dvb/adapter0/demux0",
"/dev/dvb/adapter0/demux0",
"/dev/dvb/adapter0/demux0"
};
#define NUM_DEMUX 1
static int dmx_source[NUM_DEMUX] = { 0 };
// static bool init[NUM_DEMUXDEV] = { false };
/* uuuugly */
static int dmx_tp_count = 0;
#define MAX_TS_COUNT 8
@@ -492,28 +489,12 @@ int cDemux::getUnit(void)
bool cDemux::SetSource(int unit, int source)
{
//lt_info_c("%s(%d, %d): not implemented yet\n", __func__, unit, source);
//return true;
if (unit >= NUM_DEMUX || unit < 0) {
lt_info_c("%s: unit (%d) out of range, NUM_DEMUX %d\n", __func__, unit, NUM_DEMUX);
return false;
}
lt_info_c("%s(%d, %d) => %d to %d\n", __func__, unit, source, dmx_source[unit], source);
if (source < 0 || source >= NUM_DEMUXDEV)
lt_info_c("%s(%d, %d) ERROR: source %d out of range!\n", __func__, unit, source, source);
else
dmx_source[unit] = source;
lt_info_c("%s(%d, %d): not implemented yet\n", __func__, unit, source);
return true;
}
int cDemux::GetSource(int unit)
{
//lt_info_c("%s(%d): not implemented yet\n", __func__, unit);
//return 0;
if (unit >= NUM_DEMUX || unit < 0) {
lt_info_c("%s: unit (%d) out of range, NUM_DEMUX %d\n", __func__, unit, NUM_DEMUX);
return -1;
}
lt_info_c("%s(%d) => %d\n", __func__, unit, dmx_source[unit]);
return dmx_source[unit];
lt_info_c("%s(%d): not implemented yet\n", __func__, unit);
return 0;
}

View File

@@ -97,7 +97,7 @@ GLFramebuffer::GLFramebuffer(int x, int y): mReInit(true), mShutDown(false), mIn
if (input_fd < 0)
lt_info("%s: could not open /tmp/neutrino.input FIFO: %m\n", __func__);
initKeys();
Thread::startThread();
SimpleThread::startThread();
while (!mInitDone)
usleep(1);
}
@@ -105,7 +105,7 @@ GLFramebuffer::GLFramebuffer(int x, int y): mReInit(true), mShutDown(false), mIn
GLFramebuffer::~GLFramebuffer()
{
mShutDown = true;
Thread::joinThread();
SimpleThread::joinThread();
if (input_fd >= 0)
close(input_fd);
}

View File

@@ -18,8 +18,8 @@
#ifndef __glthread__
#define __glthread__
#include <thread_abstraction.h>
#include <mutex_abstraction.h>
#include "../common/thread_abstraction.h"
#include "../common/mutex_abstraction.h"
#include <vector>
#include <map>
@@ -31,7 +31,7 @@ extern "C" {
#include <libavutil/rational.h>
}
class GLFramebuffer : public Thread
class GLFramebuffer : public SimpleThread
{
public:
GLFramebuffer(int x, int y);

View File

@@ -145,7 +145,7 @@ int cVideo::Start(void *, unsigned short, unsigned short, void *)
{
lt_debug("%s running %d >\n", __func__, thread_running);
if (!thread_running && !HAL_nodec)
Thread::startThread();
SimpleThread::startThread();
lt_debug("%s running %d <\n", __func__, thread_running);
return 0;
}
@@ -155,7 +155,7 @@ int cVideo::Stop(bool)
lt_debug("%s running %d >\n", __func__, thread_running);
if (thread_running) {
thread_running = false;
Thread::joinThread();
SimpleThread::joinThread();
}
lt_debug("%s running %d <\n", __func__, thread_running);
return 0;

View File

@@ -1,8 +1,8 @@
#ifndef _VIDEO_LIB_H
#define _VIDEO_LIB_H
#include <thread_abstraction.h>
#include <mutex_abstraction.h>
#include "../common/thread_abstraction.h"
#include "../common/mutex_abstraction.h"
#include <vector>
#include <linux/dvb/video.h>
#include "cs_types.h"
@@ -121,7 +121,7 @@ typedef enum
#define VDEC_MAXBUFS 0x30
class cVideo : public Thread
class cVideo : public SimpleThread
{
friend class GLFramebuffer;
friend class cDemux;

View File

@@ -1,23 +0,0 @@
#ifndef _CONDITION_ABSTRACTION_H
#define _CONDITION_ABSTRACTION_H
#include <pthread.h>
#include "mutex_abstraction.h"
class Condition
{
pthread_cond_t mCondition;
Condition(const Condition&);
const Condition& operator=(const Condition&);
public:
Condition();
virtual ~Condition();
virtual int wait(Mutex* const aMutex);
virtual int broadcast();
virtual int signal();
};
#endif

View File

@@ -1,16 +0,0 @@
#ifndef _REENTRANT_MUTEX_H
#define _REENTRANT_MUTEX_H
#include "mutex_abstraction.h"
class ReentrantMutex : public Mutex
{
ReentrantMutex(const ReentrantMutex&);
const ReentrantMutex& operator=(const ReentrantMutex&);
public:
ReentrantMutex();
virtual ~ReentrantMutex();
};
#endif

View File

@@ -1,18 +0,0 @@
#ifndef _SCOPED_LOCK_H
#define _SCOPED_LOCK_H
#include "mutex_abstraction.h"
class ScopedLock
{
Mutex& mMutex;
ScopedLock(const ScopedLock&);
const ScopedLock& operator=(const ScopedLock&);
public:
ScopedLock(Mutex&);
~ScopedLock();
};
#endif

View File

@@ -1,30 +0,0 @@
#ifndef _THREAD_ABSTRACTION_H
#define _THREAD_ABSTRACTION_H
#include <pthread.h>
class Thread
{
bool mIsRunning;
pthread_t mThread;
static void* runThread(void*);
Thread(const Thread&);
const Thread& operator=(const Thread&);
public:
Thread();
virtual ~Thread();
int startThread();
int cancelThread();
int detachThread();
int joinThread();
int setCancelModeDisable();
int setSchedulePriority(int);
protected:
virtual void run() = 0;
};
#endif

View File

@@ -1,16 +0,0 @@
noinst_LTLIBRARIES = libthread.la
AM_CPPFLAGS = -D__STDC_FORMAT_MACROS -D__STDC_CONSTANT_MACROS
AM_CPPFLAGS += \
-I$(top_srcdir)/include
AM_CXXFLAGS = -fno-rtti -fno-exceptions -fno-strict-aliasing
AM_LDFLAGS = -lpthread -lrt
libthread_la_SOURCES = \
condition_abstraction.cpp \
reentrant_mutex.cpp \
scoped_lock.cpp \
thread_abstraction.cpp \
mutex_abstraction.cpp

View File

@@ -1,27 +0,0 @@
#include <condition_abstraction.h>
Condition::Condition() :
mCondition()
{
pthread_cond_init(&mCondition, 0);
}
Condition::~Condition()
{
pthread_cond_destroy(&mCondition);
}
int Condition::wait(Mutex* const aMutex)
{
return pthread_cond_wait(&mCondition, &(aMutex->mMutex));
}
int Condition::broadcast()
{
return pthread_cond_broadcast(&mCondition);
}
int Condition::signal()
{
return pthread_cond_signal(&mCondition);
}

View File

@@ -1,11 +0,0 @@
#include <reentrant_mutex.h>
ReentrantMutex::ReentrantMutex() :
Mutex(PTHREAD_MUTEX_RECURSIVE)
{
}
ReentrantMutex::~ReentrantMutex()
{
//safely destroyed in ~Mutex();
}

View File

@@ -1,12 +0,0 @@
#include <scoped_lock.h>
ScopedLock::ScopedLock(Mutex& aMutex) :
mMutex(aMutex)
{
mMutex.lock();
}
ScopedLock::~ScopedLock()
{
mMutex.unlock();
}

View File

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