From 15fca75a88f925c94a19f0421cbd29a1eabc1cb5 Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Wed, 24 May 2000 22:07:10 +0000 Subject: [PATCH] fixed startup order problems without impactiing the structure of the design --- src/libCom/osi/osiThread.cpp | 32 ++++++++++++++++++++------------ src/libCom/osi/osiThread.h | 8 +++++--- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/libCom/osi/osiThread.cpp b/src/libCom/osi/osiThread.cpp index 92205479d..43d9b79be 100644 --- a/src/libCom/osi/osiThread.cpp +++ b/src/libCom/osi/osiThread.cpp @@ -7,34 +7,42 @@ #include #include -static void osiThreadCallEntryPoint (void *pPvt); // for gnu warning +static void osiThreadCallEntryPoint ( void *pPvt ); // for gnu warning #define epicsExportSharedSymbols #include "osiThread.h" -static void osiThreadCallEntryPoint (void *pPvt) +static void osiThreadCallEntryPoint ( void *pPvt ) { - osiThread *pThread = static_cast (pPvt); - pThread->entryPoint (); + osiThread *pThread = static_cast ( pPvt ); + pThread->begin.wait (); + if ( ! pThread->cancel ) { + pThread->entryPoint (); + } pThread->exit.signal (); } - -osiThread::osiThread () : id(0), exit() +osiThread::osiThread ( const char *name, unsigned stackSize, unsigned priority ) : + cancel (false) { + this->id = threadCreate ( name, priority, stackSize, + osiThreadCallEntryPoint, static_cast (this) ); } osiThread::~osiThread () { - while ( !this->exit.wait (5.0) ) { - printf ("osiThread::~osiThread ():" - " Warning, thread object destroyed before thread exit \n"); + if ( this->id ) { + this->cancel = true; + this->begin.signal (); + while ( ! this->exit.wait ( 5.0 ) ) { + printf ("osiThread::~osiThread ():" + " Warning, thread object destroyed before thread exit \n"); + } } } -void osiThread::start(const char *name, unsigned stackSize, unsigned priority) +void osiThread::start () { - id = threadCreate (name, priority, stackSize, - osiThreadCallEntryPoint, static_cast (this) ); + this->begin.signal (); } diff --git a/src/libCom/osi/osiThread.h b/src/libCom/osi/osiThread.h index fc248aea1..3f4ea910c 100644 --- a/src/libCom/osi/osiThread.h +++ b/src/libCom/osi/osiThread.h @@ -99,11 +99,11 @@ epicsShareFunc void * epicsShareAPI threadPrivateGet (threadPrivateId); class epicsShareClass osiThread { public: - osiThread(); + osiThread (const char *name, unsigned stackSize, + unsigned priority=threadPriorityLow); virtual ~osiThread (); - void start(const char *name, unsigned stackSize, - unsigned priority=threadPriorityLow); + void start(); virtual void entryPoint () = 0; @@ -124,6 +124,8 @@ public: private: threadId id; osiEvent exit; + osiEvent begin; + bool cancel; friend void osiThreadCallEntryPoint (void *pPvt); };