This is Unofficial EPICS BASE Doxygen Site
osdEvent.c
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 /* osdEvent.c */
10 /*
11  * WIN32 version
12  *
13  * Author Jeffrey O. Hill
14  * johill@lanl.gov
15  * 505 665 1831
16  *
17  */
18 
19 #include <limits.h>
20 
21 #define VC_EXTRALEAN
22 #define STRICT
23 #include <windows.h>
24 
25 #include "libComAPI.h"
26 #include "epicsEvent.h"
27 
28 typedef struct epicsEventOSD {
29  HANDLE handle;
31 
32 /*
33  * epicsEventCreate ()
34  */
36  epicsEventInitialState initialState )
37 {
38  epicsEventOSD *pSem;
39 
40  pSem = malloc ( sizeof ( *pSem ) );
41  if ( pSem ) {
42  pSem->handle = CreateEvent ( NULL, FALSE, initialState?TRUE:FALSE, NULL );
43  if ( pSem->handle == 0 ) {
44  free ( pSem );
45  pSem = 0;
46  }
47  }
48 
49  return pSem;
50 }
51 
52 /*
53  * epicsEventDestroy ()
54  */
55 LIBCOM_API void epicsEventDestroy ( epicsEventId pSem )
56 {
57  CloseHandle ( pSem->handle );
58  free ( pSem );
59 }
60 
61 /*
62  * epicsEventTrigger ()
63  */
65 {
66  BOOL status;
67  status = SetEvent ( pSem->handle );
68  return status ? epicsEventOK : epicsEventError;
69 }
70 
71 /*
72  * epicsEventWait ()
73  */
75 {
76  DWORD status;
77  status = WaitForSingleObject (pSem->handle, INFINITE);
78  if ( status == WAIT_OBJECT_0 ) {
79  return epicsEventOK;
80  }
81  else {
82  return epicsEventError;
83  }
84 }
85 
86 /*
87  * epicsEventWaitWithTimeout ()
88  */
90  epicsEventId pSem, double timeOut )
91 {
92  static const unsigned mSecPerSec = 1000;
93  DWORD status;
94  DWORD tmo;
95 
96  if ( timeOut <= 0.0 ) {
97  tmo = 0u;
98  }
99  else if ( timeOut >= INFINITE / mSecPerSec ) {
100  tmo = INFINITE - 1;
101  }
102  else {
103  tmo = ( DWORD ) ( ( timeOut * mSecPerSec ) + 0.5 );
104  if ( tmo == 0 ) {
105  tmo = 1;
106  }
107  }
108  status = WaitForSingleObject ( pSem->handle, tmo );
109  if ( status == WAIT_OBJECT_0 ) {
110  return epicsEventOK;
111  }
112  else if ( status == WAIT_TIMEOUT ) {
113  return epicsEventWaitTimeout;
114  }
115  else {
116  return epicsEventError;
117  }
118 }
119 
120 /*
121  * epicsEventTryWait ()
122  */
124 {
125  DWORD status;
126 
127  status = WaitForSingleObject ( pSem->handle, 0 );
128  if ( status == WAIT_OBJECT_0 ) {
129  return epicsEventOK;
130  }
131  else if ( status == WAIT_TIMEOUT ) {
132  return epicsEventWaitTimeout;
133  }
134  else {
135  return epicsEventError;
136  }
137 }
138 
139 /*
140  * epicsEventShow ()
141  */
142 LIBCOM_API void epicsEventShow ( epicsEventId id, unsigned level )
143 {
144 }
#define FALSE
Definition: dbDefs.h:32
pvd::Status status
LIBCOM_API epicsEventStatus epicsEventWaitWithTimeout(epicsEventId pevent, double timeout)
Wait an the event or until the specified timeout period is over.
Definition: osdEvent.c:117
#define NULL
Definition: catime.c:38
LIBCOM_API epicsEventStatus epicsEventTrigger(epicsEventId pevent)
Trigger an event i.e. ensures the next or current call to wait completes.
Definition: osdEvent.c:80
struct epicsEventOSD epicsEventOSD
LIBCOM_API epicsEventId epicsEventCreate(epicsEventInitialState init)
Create an epicsEvent for use from C code, or return NULL.
Definition: osdEvent.c:47
LIBCOM_API void epicsEventShow(epicsEventId pevent, unsigned int level)
Display information about the semaphore.
Definition: osdEvent.c:150
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
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
#define TRUE
Definition: dbDefs.h:27
LIBCOM_API epicsEventStatus epicsEventWait(epicsEventId pevent)
Wait for an event.
Definition: osdEvent.c:95
const unsigned mSecPerSec
Definition: fdManager.cpp:34
HANDLE handle
Definition: osdEvent.c:29
LIBCOM_API void epicsEventDestroy(epicsEventId pevent)
Destroy an epicsEvent and any resources it holds.
Definition: osdEvent.c:70