diff --git a/src/libCom/osi/osiEvent.h b/src/libCom/osi/osiEvent.h new file mode 100644 index 000000000..f1b8b6bc9 --- /dev/null +++ b/src/libCom/osi/osiEvent.h @@ -0,0 +1,98 @@ + +#include "osiSem.h" +#include "shareLib.h" + +class epicsShareClass osiEvent { +public: + osiEvent (); + ~osiEvent (); + void signal (); + void wait (); /* blocks until full */ + bool wait (double timeOut); /* false if empty at time out */ + bool tryWait (); /* false if empty */ + void show (unsigned level); + + class invalidSemaphore {}; /* exception */ + class noMemory {}; /* exception */ +private: + semBinaryId id; +}; + +inline osiEvent::osiEvent () +{ + this->id = semBinaryCreate (semEmpty); + if (this->id==0) { +# ifdef noExceptionsFromCXX + assert (0); +# else + throw noMemory (); +# endif + } +} + +inline osiEvent::~osiEvent () +{ + semBinaryDestroy (this->id); +} + +inline void osiEvent::signal () +{ + semBinaryGive (this->id); +} + +inline void osiEvent::wait () +{ + semTakeStatus status; + status = semBinaryTake (this->id); + if (status!=semTakeOK) { +# ifdef noExceptionsFromCXX + assert (0); +# else + throw invalidSemaphore (); +# endif + } +} + +inline bool osiEvent::wait (double timeOut) +{ + semTakeStatus status; + status = semBinaryTakeTimeout (this->id, timeOut); + if (status==semTakeOK) { + return true; + } + else if (status==semTakeTimeout) { + return false; + } + else { +# ifdef noExceptionsFromCXX + assert (0); +# else + throw invalidSemaphore (); +# endif + } +} + +inline bool osiEvent::tryWait () +{ + semTakeStatus status; + status = semBinaryTakeNoWait (this->id); + if (status==semTakeOK) { + return true; + } + else if (status==semTakeTimeout) { + return false; + } + else { +# ifdef noExceptionsFromCXX + assert (0); +# else + throw invalidSemaphore (); +# endif + } +} + +inline void osiEvent::show (unsigned level) +{ + semBinaryShow (this->id, level); +} + diff --git a/src/libCom/osi/osiMutex.h b/src/libCom/osi/osiMutex.h new file mode 100644 index 000000000..0aba24d2c --- /dev/null +++ b/src/libCom/osi/osiMutex.h @@ -0,0 +1,97 @@ + +#include "osiSem.h" +#include "shareLib.h" + +class epicsShareClass osiMutex { +public: + osiMutex (); + ~osiMutex (); + void lock () const; /* blocks until success */ + bool lock (double timeOut) const; /* true if successful */ + bool tryLock () const; /* true if successful */ + void unlock () const; + void show (unsigned level) const; + + class invalidSemaphore {}; /* exception */ + class noMemory {}; /* exception */ +private: + mutable semMutexId id; +}; + +inline osiMutex::osiMutex () +{ + this->id = semMutexCreate (); + if (this->id==0) { +# ifdef noExceptionsFromCXX + assert (0); +# else + throw noMemory (); +# endif + } +} + +inline osiMutex::~osiMutex () +{ + semMutexDestroy (this->id); +} + +inline void osiMutex::lock () const +{ + semTakeStatus status; + status = semMutexTake (this->id); + if (status!=semTakeOK) { +# ifdef noExceptionsFromCXX + assert (0); +# else + throw invalidSemaphore (); +# endif + } +} + +inline bool osiMutex::lock (double timeOut) const +{ + semTakeStatus status; + status = semMutexTakeTimeout (this->id, timeOut); + if (status==semTakeOK) { + return true; + } + else if (status==semTakeTimeout) { + return false; + } + else { +# ifdef noExceptionsFromCXX + assert (0); +# else + throw invalidSemaphore (); +# endif + } +} + +inline bool osiMutex::tryLock () const +{ + semTakeStatus status; + status = semMutexTakeNoWait (this->id); + if (status==semTakeOK) { + return true; + } + else if (status==semTakeTimeout) { + return false; + } + else { +# ifdef noExceptionsFromCXX + assert (0); +# else + throw invalidSemaphore (); +# endif + } +} + +inline void osiMutex::unlock () const +{ + semMutexGive (this->id); +} + +inline void osiMutex::show (unsigned level) const +{ + semMutexShow (this->id, level); +} \ No newline at end of file diff --git a/src/libCom/osi/osiThread.cpp b/src/libCom/osi/osiThread.cpp new file mode 100644 index 000000000..98f4a341b --- /dev/null +++ b/src/libCom/osi/osiThread.cpp @@ -0,0 +1,21 @@ +// +// $Id$ +// +// Author: Jeff Hill +// + +#define epicsExportSharedSymbols +#include "osiThread.h" + +static void osiThreadCallEntryPoint (void *pPvt) +{ + osiThread *pThread = static_cast (pPvt); + pThread->entryPoint (); +} + +osiThread::osiThread (const char *name, unsigned stackSize, + unsigned priority) +{ + this->id = threadCreate (name, priority, stackSize, + osiThreadCallEntryPoint, static_cast (this) ); +}