From 1aece863c11038f05c824ecb2a1ed1f72f1ef295 Mon Sep 17 00:00:00 2001 From: max_10 Date: Thu, 20 Sep 2018 17:42:13 +0200 Subject: [PATCH] Revert "move libthread to libstb-hal" This reverts commit 95ee7f9e98451a7199cfeb2c8c0dbcd9bbb370f5. --- Makefile.am | 5 +- common/Makefile.am | 2 + {libthread => common}/mutex_abstraction.cpp | 12 +---- {include => common}/mutex_abstraction.h | 9 +--- common/thread_abstraction.cpp | 34 ++++++++++++ common/thread_abstraction.h | 25 +++++++++ configure.ac | 1 - generic-pc/audio.cpp | 4 +- generic-pc/audio_lib.h | 3 +- generic-pc/dmx.cpp | 31 +++-------- generic-pc/glfb.cpp | 4 +- generic-pc/glfb.h | 6 +-- generic-pc/video.cpp | 4 +- generic-pc/video_lib.h | 6 +-- include/condition_abstraction.h | 23 -------- include/reentrant_mutex.h | 16 ------ include/scoped_lock.h | 18 ------- include/thread_abstraction.h | 30 ----------- libthread/Makefile.am | 16 ------ libthread/condition_abstraction.cpp | 27 ---------- libthread/reentrant_mutex.cpp | 11 ---- libthread/scoped_lock.cpp | 12 ----- libthread/thread_abstraction.cpp | 58 --------------------- 23 files changed, 85 insertions(+), 272 deletions(-) rename {libthread => common}/mutex_abstraction.cpp (52%) rename {include => common}/mutex_abstraction.h (68%) create mode 100644 common/thread_abstraction.cpp create mode 100644 common/thread_abstraction.h delete mode 100644 include/condition_abstraction.h delete mode 100644 include/reentrant_mutex.h delete mode 100644 include/scoped_lock.h delete mode 100644 include/thread_abstraction.h delete mode 100644 libthread/Makefile.am delete mode 100644 libthread/condition_abstraction.cpp delete mode 100644 libthread/reentrant_mutex.cpp delete mode 100644 libthread/scoped_lock.cpp delete mode 100644 libthread/thread_abstraction.cpp diff --git a/Makefile.am b/Makefile.am index 5466534..c26789f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/common/Makefile.am b/common/Makefile.am index 17395fc..86f3517 100644 --- a/common/Makefile.am +++ b/common/Makefile.am @@ -31,6 +31,8 @@ endif endif libcommon_la_SOURCES += \ + thread_abstraction.cpp \ + mutex_abstraction.cpp \ lt_debug.cpp \ proc_tools.c \ pwrmngr.cpp diff --git a/libthread/mutex_abstraction.cpp b/common/mutex_abstraction.cpp similarity index 52% rename from libthread/mutex_abstraction.cpp rename to common/mutex_abstraction.cpp index 906407a..a5a886f 100644 --- a/libthread/mutex_abstraction.cpp +++ b/common/mutex_abstraction.cpp @@ -1,4 +1,4 @@ -#include +#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); diff --git a/include/mutex_abstraction.h b/common/mutex_abstraction.h similarity index 68% rename from include/mutex_abstraction.h rename to common/mutex_abstraction.h index 3ea5357..c2b78d8 100644 --- a/include/mutex_abstraction.h +++ b/common/mutex_abstraction.h @@ -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 diff --git a/common/thread_abstraction.cpp b/common/thread_abstraction.cpp new file mode 100644 index 0000000..0494fc4 --- /dev/null +++ b/common/thread_abstraction.cpp @@ -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(ptr)->run(); + return 0; +} diff --git a/common/thread_abstraction.h b/common/thread_abstraction.h new file mode 100644 index 0000000..45a20b6 --- /dev/null +++ b/common/thread_abstraction.h @@ -0,0 +1,25 @@ +#ifndef _SIMPLETHREAD_ABSTRACTION_H +#define _SIMPLETHREAD_ABSTRACTION_H + +#include + +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 diff --git a/configure.ac b/configure.ac index 202eaaf..cac007d 100644 --- a/configure.ac +++ b/configure.ac @@ -76,7 +76,6 @@ Makefile common/Makefile libeplayer3/Makefile libeplayer3-arm/Makefile -libthread/Makefile azbox/Makefile generic-pc/Makefile libduckbox/Makefile diff --git a/generic-pc/audio.cpp b/generic-pc/audio.cpp index 1bba357..0ee8b3b 100644 --- a/generic-pc/audio.cpp +++ b/generic-pc/audio.cpp @@ -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; diff --git a/generic-pc/audio_lib.h b/generic-pc/audio_lib.h index dc09c8d..6bcd80a 100644 --- a/generic-pc/audio_lib.h +++ b/generic-pc/audio_lib.h @@ -4,7 +4,6 @@ #define _AUDIO_LIB_H_ #include -#include #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: diff --git a/generic-pc/dmx.cpp b/generic-pc/dmx.cpp index 1af785f..769a971 100644 --- a/generic-pc/dmx.cpp +++ b/generic-pc/dmx.cpp @@ -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; } diff --git a/generic-pc/glfb.cpp b/generic-pc/glfb.cpp index a838997..3cffd0e 100644 --- a/generic-pc/glfb.cpp +++ b/generic-pc/glfb.cpp @@ -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); } diff --git a/generic-pc/glfb.h b/generic-pc/glfb.h index 6cb803d..755a01f 100644 --- a/generic-pc/glfb.h +++ b/generic-pc/glfb.h @@ -18,8 +18,8 @@ #ifndef __glthread__ #define __glthread__ -#include -#include +#include "../common/thread_abstraction.h" +#include "../common/mutex_abstraction.h" #include #include @@ -31,7 +31,7 @@ extern "C" { #include } -class GLFramebuffer : public Thread +class GLFramebuffer : public SimpleThread { public: GLFramebuffer(int x, int y); diff --git a/generic-pc/video.cpp b/generic-pc/video.cpp index abcfd75..06ea690 100644 --- a/generic-pc/video.cpp +++ b/generic-pc/video.cpp @@ -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; diff --git a/generic-pc/video_lib.h b/generic-pc/video_lib.h index a8274e8..144b53f 100644 --- a/generic-pc/video_lib.h +++ b/generic-pc/video_lib.h @@ -1,8 +1,8 @@ #ifndef _VIDEO_LIB_H #define _VIDEO_LIB_H -#include -#include +#include "../common/thread_abstraction.h" +#include "../common/mutex_abstraction.h" #include #include #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; diff --git a/include/condition_abstraction.h b/include/condition_abstraction.h deleted file mode 100644 index 8374efa..0000000 --- a/include/condition_abstraction.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef _CONDITION_ABSTRACTION_H -#define _CONDITION_ABSTRACTION_H - -#include - -#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 diff --git a/include/reentrant_mutex.h b/include/reentrant_mutex.h deleted file mode 100644 index bf9f740..0000000 --- a/include/reentrant_mutex.h +++ /dev/null @@ -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 diff --git a/include/scoped_lock.h b/include/scoped_lock.h deleted file mode 100644 index 0c1fdb2..0000000 --- a/include/scoped_lock.h +++ /dev/null @@ -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 diff --git a/include/thread_abstraction.h b/include/thread_abstraction.h deleted file mode 100644 index 12f9f76..0000000 --- a/include/thread_abstraction.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef _THREAD_ABSTRACTION_H -#define _THREAD_ABSTRACTION_H - -#include - -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 diff --git a/libthread/Makefile.am b/libthread/Makefile.am deleted file mode 100644 index 9369b1f..0000000 --- a/libthread/Makefile.am +++ /dev/null @@ -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 diff --git a/libthread/condition_abstraction.cpp b/libthread/condition_abstraction.cpp deleted file mode 100644 index 68d246a..0000000 --- a/libthread/condition_abstraction.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include - -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); -} diff --git a/libthread/reentrant_mutex.cpp b/libthread/reentrant_mutex.cpp deleted file mode 100644 index 82c3069..0000000 --- a/libthread/reentrant_mutex.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include - -ReentrantMutex::ReentrantMutex() : - Mutex(PTHREAD_MUTEX_RECURSIVE) -{ -} - -ReentrantMutex::~ReentrantMutex() -{ - //safely destroyed in ~Mutex(); -} diff --git a/libthread/scoped_lock.cpp b/libthread/scoped_lock.cpp deleted file mode 100644 index 7ff573d..0000000 --- a/libthread/scoped_lock.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include - -ScopedLock::ScopedLock(Mutex& aMutex) : - mMutex(aMutex) -{ - mMutex.lock(); -} - -ScopedLock::~ScopedLock() -{ - mMutex.unlock(); -} diff --git a/libthread/thread_abstraction.cpp b/libthread/thread_abstraction.cpp deleted file mode 100644 index afaff86..0000000 --- a/libthread/thread_abstraction.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include - -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(ptr); - t->run(); - return 0; -}