mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-libstb-hal.git
synced 2025-08-26 15:02:43 +02:00
Revert "move libthread to libstb-hal"
This reverts commitd5cea508e0
. Origin commit data ------------------ Branch: master Commit:6b8b8cd551
Author: max_10 <max_10@gmx.de> Date: 2018-09-20 (Thu, 20 Sep 2018) ------------------ This commit was generated by Migit
This commit is contained in:
@@ -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
|
||||
|
@@ -31,6 +31,8 @@ endif
|
||||
endif
|
||||
|
||||
libcommon_la_SOURCES += \
|
||||
thread_abstraction.cpp \
|
||||
mutex_abstraction.cpp \
|
||||
lt_debug.cpp \
|
||||
proc_tools.c \
|
||||
pwrmngr.cpp
|
||||
|
@@ -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);
|
@@ -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
|
34
common/thread_abstraction.cpp
Normal file
34
common/thread_abstraction.cpp
Normal 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;
|
||||
}
|
25
common/thread_abstraction.h
Normal file
25
common/thread_abstraction.h
Normal 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
|
@@ -76,7 +76,6 @@ Makefile
|
||||
common/Makefile
|
||||
libeplayer3/Makefile
|
||||
libeplayer3-arm/Makefile
|
||||
libthread/Makefile
|
||||
azbox/Makefile
|
||||
generic-pc/Makefile
|
||||
libduckbox/Makefile
|
||||
|
@@ -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;
|
||||
|
@@ -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:
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -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);
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
#include <reentrant_mutex.h>
|
||||
|
||||
ReentrantMutex::ReentrantMutex() :
|
||||
Mutex(PTHREAD_MUTEX_RECURSIVE)
|
||||
{
|
||||
}
|
||||
|
||||
ReentrantMutex::~ReentrantMutex()
|
||||
{
|
||||
//safely destroyed in ~Mutex();
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
#include <scoped_lock.h>
|
||||
|
||||
ScopedLock::ScopedLock(Mutex& aMutex) :
|
||||
mMutex(aMutex)
|
||||
{
|
||||
mMutex.lock();
|
||||
}
|
||||
|
||||
ScopedLock::~ScopedLock()
|
||||
{
|
||||
mMutex.unlock();
|
||||
}
|
@@ -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;
|
||||
}
|
Reference in New Issue
Block a user