From 3d698c76cdf3ce815c1ae81b12a711e5f1f99f65 Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Mon, 7 Feb 2000 21:38:05 +0000 Subject: [PATCH] many C++ related changes --- src/libCom/osi/osiThread.h | 133 +++++++++++++++++++++++++++++++++---- 1 file changed, 119 insertions(+), 14 deletions(-) diff --git a/src/libCom/osi/osiThread.h b/src/libCom/osi/osiThread.h index 43fc5b923..d6f2d65ed 100644 --- a/src/libCom/osi/osiThread.h +++ b/src/libCom/osi/osiThread.h @@ -34,7 +34,7 @@ typedef void *threadId; epicsShareFunc threadId epicsShareAPI threadCreate(const char *name, unsigned int priority, unsigned int stackSize, THREADFUNC funptr,void *parm); -epicsShareFunc void epicsShareAPI threadSuspend(); +epicsShareFunc void epicsShareAPI threadSuspend(void); epicsShareFunc void epicsShareAPI threadResume(threadId id); epicsShareFunc unsigned int epicsShareAPI threadGetPriority(threadId id); epicsShareFunc void epicsShareAPI threadSetPriority( @@ -46,8 +46,8 @@ epicsShareFunc void epicsShareAPI threadSleep(double seconds); epicsShareFunc threadId epicsShareAPI threadGetIdSelf(void); typedef void * threadVarId; -epicsShareFunc threadVarId epicsShareAPI threadPrivateCreate (); -epicsShareFunc void epicsShareAPI threadPrivateDelete (); +epicsShareFunc threadVarId epicsShareAPI threadPrivateCreate (void); +epicsShareFunc void epicsShareAPI threadPrivateDelete (threadVarId id); epicsShareFunc void epicsShareAPI threadPrivateSet (threadVarId, void *); epicsShareFunc void * epicsShareAPI threadPrivateGet (threadVarId); @@ -57,41 +57,146 @@ epicsShareFunc void * epicsShareAPI threadPrivateGet (threadVarId); #ifdef __cplusplus -class osiThread : private osdThread { +class osiThread { public: - osiThread (const char *name, threadStackSizeClass = threadStackBig, + osiThread (const char *name, unsigned stackSize, unsigned priority=threadPriorityLow); - //osiThread (const char *name, unsigned stackSize, - // unsigned priority=threadPriorityLow); - ~osiThread(); virtual void entryPoint () = 0; void suspend (); void resume (); - unsigned getPriority (); + unsigned getPriority () const; void setPriority (unsigned); - bool priorityIsEqual (osiThread &otherThread); - bool isReady (); - bool isSuspended (); + bool priorityIsEqual (const osiThread &otherThread) const; + bool isReady () const; + bool isSuspended () const; - operator == (); + bool operator == (const osiThread &rhs) const; /* these operate on the current thread */ static void sleep (double seconds); static osiThread & getSelf (); +private: + threadId id; }; template -class osiThreadPrivate : private osdThreadPrivate { +class osiThreadPrivate { public: + osiThreadPrivate (); + ~osiThreadPrivate (); T *get () const; void set (T *); class unableToCreateThreadPrivate {}; // exception +private: + threadVarId id; }; #endif /* __cplusplus */ #include "osdThread.h" +#ifdef __cplusplus + +#include + +inline void osiThread::suspend () +{ + threadSuspend (); +} + +inline void osiThread::resume () +{ + threadResume (this->id); +} + +inline unsigned osiThread::getPriority () const +{ + return threadGetPriority (this->id); +} + +inline void osiThread::setPriority (unsigned priority) +{ + threadSetPriority (this->id, priority); +} + +inline bool osiThread::priorityIsEqual (const osiThread &otherThread) const +{ + if ( threadIsEqual (this->id, otherThread.id) ) { + return true; + } + else { + return false; + } +} + +inline bool osiThread::isReady () const +{ + if ( threadIsReady (this->id) ) { + return true; + } + else { + return false; + } +} + +inline bool osiThread::isSuspended () const +{ + if ( threadIsSuspended (this->id) ) { + return true; + } + else { + return false; + } +} + +inline bool osiThread::operator == (const osiThread &rhs) const +{ + return (this->id == rhs.id); +} + +inline void osiThread::sleep (double seconds) +{ + threadSleep (seconds); +} + +inline osiThread & osiThread::getSelf () +{ + return * static_cast ( threadGetIdSelf () ); +} + +template +inline osiThreadPrivate::osiThreadPrivate () +{ + this->id = threadPrivateCreate (); + if (this->id == 0) { +# ifdef noExceptionsFromCXX + assert (this->id != 0); +# else + throw unableToCreateThreadPrivate (); +# endif + } +} + +template +inline osiThreadPrivate::~osiThreadPrivate () +{ + threadPrivateDelete ( this->id ); +} + +template +inline T *osiThreadPrivate::get () const +{ + return static_cast ( threadPrivateGet (this->id) ); +} + +template +inline void osiThreadPrivate::set (T *pIn) +{ + threadPrivateSet ( this->id, static_cast (pIn) ); +} + +#endif /* ifdef __cplusplus */ + #endif /* osiThreadh */