* Renamed the enum epicsEventWaitStatus to epicsEventStatus
* Defined epicsEventWaitStatus as a macro for epicsEventStatus
* Renamed epicsEventWaitOk to epicsEventOk
* Renamed epicsEventWaitError to epicsEventError
* Defined epicsEventWaitOK and epicsEventWaitError as macros
* Added epicsEventTrigger(id) which triggers an event and returns OK or an
error status if the underlying OS primitives report an error
* Added epicsEventMustTrigger(id) which halts on error
* Defined epicsEventSignal(id) as a macro for epicsEventMustTrigger(id)
* Added a new C++ method epicsEvent::trigger() which throws an
epicsEvent::invalidSemaphore in the event of an error
* epicsEvent::signal() makes an inline call to epicsEvent::trigger()
* epicsEventWait() and epicsEventWaitWithTimeout() now return an error
status if the underlying OS primitives report an error
* All the epicsEventMust...() routines are now implemented in the common
libCom/osi/epicsEvent.cpp source file, and call cantProceed() instead of
mis-using assert()
* Implemented epicsEventShow() on Posix
133 lines
3.1 KiB
C++
133 lines
3.1 KiB
C++
/*************************************************************************\
|
|
* Copyright (c) 2011 UChicago Argonne LLC, as Operator of Argonne
|
|
* National Laboratory.
|
|
* Copyright (c) 2002 The Regents of the University of California, as
|
|
* Operator of Los Alamos National Laboratory.
|
|
* EPICS BASE is distributed subject to a Software License Agreement found
|
|
* in file LICENSE that is included with this distribution.
|
|
\*************************************************************************/
|
|
|
|
/* epicsMutex.c */
|
|
/* Author: Jeff Hill */
|
|
|
|
#include <new>
|
|
#include <exception>
|
|
|
|
#define epicsExportSharedSymbols
|
|
#include "epicsEvent.h"
|
|
#include "epicsStdioRedirect.h"
|
|
#include "cantProceed.h"
|
|
|
|
// vxWorks 5.4 gcc fails during compile when I use std::exception
|
|
using namespace std;
|
|
|
|
// exception payload
|
|
class epicsEvent::invalidSemaphore : public exception
|
|
{
|
|
const char * what () const throw ();
|
|
};
|
|
|
|
const char * epicsEvent::invalidSemaphore::what () const throw ()
|
|
{
|
|
return "epicsEvent::invalidSemaphore()";
|
|
}
|
|
|
|
//
|
|
// Its probably preferable to not make these inline because they are in
|
|
// the sharable library interface. The use of inline or not here is probably
|
|
// not an issue because all of this ends up in the operating system in system
|
|
// calls
|
|
//
|
|
|
|
epicsEvent::epicsEvent ( epicsEventInitialState initial ) :
|
|
id ( epicsEventCreate ( initial ) )
|
|
{
|
|
if ( this->id == 0 ) {
|
|
throw std::bad_alloc ();
|
|
}
|
|
}
|
|
|
|
epicsEvent::~epicsEvent ()
|
|
{
|
|
epicsEventDestroy ( this->id );
|
|
}
|
|
|
|
void epicsEvent::trigger ()
|
|
{
|
|
epicsEventStatus status = epicsEventTrigger (this->id);
|
|
|
|
if (status != epicsEventOK) {
|
|
throw invalidSemaphore ();
|
|
}
|
|
}
|
|
|
|
void epicsEvent::wait ()
|
|
{
|
|
epicsEventStatus status = epicsEventWait (this->id);
|
|
|
|
if (status != epicsEventOK) {
|
|
throw invalidSemaphore ();
|
|
}
|
|
}
|
|
|
|
bool epicsEvent::wait (double timeOut)
|
|
{
|
|
epicsEventStatus status = epicsEventWaitWithTimeout (this->id, timeOut);
|
|
|
|
if (status == epicsEventOK) {
|
|
return true;
|
|
} else if (status == epicsEventWaitTimeout) {
|
|
return false;
|
|
}
|
|
throw invalidSemaphore ();
|
|
}
|
|
|
|
bool epicsEvent::tryWait ()
|
|
{
|
|
epicsEventStatus status = epicsEventTryWait (this->id);
|
|
|
|
if (status == epicsEventOK) {
|
|
return true;
|
|
} else if (status == epicsEventWaitTimeout) {
|
|
return false;
|
|
}
|
|
throw invalidSemaphore ();
|
|
}
|
|
|
|
void epicsEvent::show ( unsigned level ) const
|
|
{
|
|
epicsEventShow ( this->id, level );
|
|
}
|
|
|
|
|
|
// epicsEventMust... convenience routines for C code
|
|
|
|
extern "C" {
|
|
|
|
epicsShareFunc epicsEventId epicsEventMustCreate (
|
|
epicsEventInitialState initialState)
|
|
{
|
|
epicsEventId id = epicsEventCreate (initialState);
|
|
|
|
if (!id)
|
|
cantProceed ("epicsEventMustCreate");
|
|
return id;
|
|
}
|
|
|
|
epicsShareFunc void epicsEventMustTrigger (epicsEventId id) {
|
|
epicsEventStatus status = epicsEventTrigger (id);
|
|
|
|
if (status != epicsEventOK)
|
|
cantProceed ("epicsEventMustTrigger");
|
|
}
|
|
|
|
epicsShareFunc void epicsEventMustWait (epicsEventId id) {
|
|
epicsEventStatus status = epicsEventWait (id);
|
|
|
|
if (status != epicsEventOK)
|
|
cantProceed ("epicsEventMustWait");
|
|
}
|
|
|
|
} // extern "C"
|
|
|