This is Unofficial EPICS BASE Doxygen Site
epicsEvent.cpp
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2011 UChicago Argonne LLC, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The Regents of the University of California, as
5 * Operator of Los Alamos National Laboratory.
6 * EPICS BASE is distributed subject to a Software License Agreement found
7 * in file LICENSE that is included with this distribution.
8 \*************************************************************************/
9 
10 /* epicsMutex.c */
11 /* Author: Jeff Hill */
12 
13 #include <new>
14 #include <exception>
15 
16 #include "epicsEvent.h"
17 #include "epicsStdio.h"
18 #include "cantProceed.h"
19 
20 // vxWorks 5.4 gcc fails during compile when I use std::exception
21 using namespace std;
22 
23 // exception payload
24 class epicsEvent::invalidSemaphore : public exception
25 {
26  const char * what () const throw ();
27 };
28 
29 const char * epicsEvent::invalidSemaphore::what () const throw ()
30 {
31  return "epicsEvent::invalidSemaphore()";
32 }
33 
34 //
35 // Its probably preferable to not make these inline because they are in
36 // the sharable library interface. The use of inline or not here is probably
37 // not an issue because all of this ends up in the operating system in system
38 // calls
39 //
40 
41 epicsEvent::epicsEvent ( epicsEventInitialState initial ) :
42  id ( epicsEventCreate ( initial ) )
43 {
44  if ( this->id == 0 ) {
45  throw std::bad_alloc ();
46  }
47 }
48 
49 epicsEvent::~epicsEvent ()
50 {
51  epicsEventDestroy ( this->id );
52 }
53 
54 void epicsEvent::trigger ()
55 {
57 
58  if (status != epicsEventOK) {
59  throw invalidSemaphore ();
60  }
61 }
62 
63 void epicsEvent::wait ()
64 {
66 
67  if (status != epicsEventOK) {
68  throw invalidSemaphore ();
69  }
70 }
71 
72 bool epicsEvent::wait (double timeOut)
73 {
75 
76  if (status == epicsEventOK) {
77  return true;
78  } else if (status == epicsEventWaitTimeout) {
79  return false;
80  }
81  throw invalidSemaphore ();
82 }
83 
84 bool epicsEvent::tryWait ()
85 {
87 
88  if (status == epicsEventOK) {
89  return true;
90  } else if (status == epicsEventWaitTimeout) {
91  return false;
92  }
93  throw invalidSemaphore ();
94 }
95 
96 void epicsEvent::show ( unsigned level ) const
97 {
98  epicsEventShow ( this->id, level );
99 }
100 
101 
102 // epicsEventMust... convenience routines for C code
103 
104 extern "C" {
105 
107  epicsEventInitialState initialState)
108 {
109  epicsEventId id = epicsEventCreate (initialState);
110 
111  if (!id)
112  cantProceed ("epicsEventMustCreate");
113  return id;
114 }
115 
116 LIBCOM_API void epicsEventMustTrigger (epicsEventId id) {
118 
119  if (status != epicsEventOK)
120  cantProceed ("epicsEventMustTrigger");
121 }
122 
123 LIBCOM_API void epicsEventMustWait (epicsEventId id) {
125 
126  if (status != epicsEventOK)
127  cantProceed ("epicsEventMustWait");
128 }
129 
130 } // extern "C"
131 
LIBCOM_API void epicsEventMustTrigger(epicsEventId id)
Trigger an event.
Definition: epicsEvent.cpp:116
pvd::Status status
#define epicsEventWait(ID)
Definition: osdEvent.h:19
Definition: memory.hpp:41
LIBCOM_API epicsEventStatus epicsEventWaitWithTimeout(epicsEventId id, double timeOut)
Wait an the event or until the specified timeout period is over.
Definition: osdEvent.c:117
LIBCOM_API epicsEventId epicsEventMustCreate(epicsEventInitialState initialState)
Create an epicsEvent for use from C code.
Definition: epicsEvent.cpp:106
#define epicsEventTrigger(ID)
Definition: osdEvent.h:16
LIBCOM_API void epicsEventMustWait(epicsEventId id)
Wait for an event (see epicsEventWait()).
Definition: epicsEvent.cpp:123
LIBCOM_API void epicsEventDestroy(epicsEventId id)
Destroy an epicsEvent and any resources it holds.
Definition: osdEvent.c:70
APIs for the epicsEvent binary semaphore.
epicsEventStatus
Return status from several C API routines.
Definition: epicsEvent.h:49
epicsEventInitialState
Possible initial states of a new epicsEvent.
Definition: epicsEvent.h:63
LIBCOM_API epicsEventStatus epicsEventTryWait(epicsEventId id)
Similar to wait() except that if the event is currenly empty the call will return immediately with st...
Definition: osdEvent.c:145
LIBCOM_API void cantProceed(const char *msg,...)
Definition: cantProceed.c:54
Routines for code that can&#39;t continue or return after an error.
LIBCOM_API epicsEventId epicsEventCreate(epicsEventInitialState initialState)
Create an epicsEvent for use from C code, or return NULL.
Definition: osdEvent.c:47
LIBCOM_API void epicsEventShow(epicsEventId id, unsigned int level)
Display information about the semaphore.
Definition: osdEvent.c:150