Merge lp:~anj/epics-base/epicsEvent-api into lp:~epics-core/epics-base/3.15

Proposed by Andrew Johnson
Status: Merged
Merged at revision: 12238
Proposed branch: lp:~anj/epics-base/epicsEvent-api
Merge into: lp:~epics-core/epics-base/3.15
Diff against target: 911 lines (+287/-269)
8 files modified
documentation/RELEASE_NOTES.html (+24/-0)
src/libCom/osi/epicsEvent.cpp (+54/-22)
src/libCom/osi/epicsEvent.h (+37/-31)
src/libCom/osi/os/RTEMS/osdEvent.c (+18/-23)
src/libCom/osi/os/WIN32/osdEvent.c (+17/-30)
src/libCom/osi/os/posix/osdEvent.c (+124/-137)
src/libCom/osi/os/vxWorks/osdEvent.c (+8/-16)
src/libCom/osi/os/vxWorks/osdEvent.h (+5/-10)
To merge this branch: bzr merge lp:~anj/epics-base/epicsEvent-api
Reviewer Review Type Date Requested Status
EPICS Core Developers Pending
Review via email: mp+48992@code.launchpad.net

Description of the change

This branch modifies the epicsEvent APIs for both C and C++ callers, but keeping full backwards compatibility.

The enum epicsEventWaitStatus is renamed to epicsEventStatus, with similar name changes for the choices except for epicsEventWaitTimeout which is unchanged. Macros are provided to allow continued use of the old names.

It adds two new routines to the C API:
 + epicsEventTrigger(id) replaces epicsEventSignal(id) but returns an epicsEventStatus so it can flag any errors from the implementation routines.
 + epicsEventMustTrigger(id) calls epicsEventTrigger(id) and suspends the calling thread on error.

epicsEventSignal(id) is now a macro that calls epicsEventMustTrigger(id).

epicsEventWait() and epicsEventWaitWithTimeout() now report errors from the implementation on all architectures; previously some architectures would suspend the thread instead.

All the epicsEventMust...() routines are now implemented in the common epicsEvent.cpp source file, and properly call cantProceed() instead of mis-using assert() in the event of any errors.

The Posix implementation now provides a basic epicsEventShow() routine.

For the C++ API it adds an epicsEvent::trigger() method that will throw an epicsEvent::invalidSemaphore exception on receiving an error.

The epicsEvent::signal() method is now an inline call to epicsEvent::trigger(), although I wonder whether signal() should halt on error like it used to instead of throwing.

The epicsShareAPI decorations (used on Windows only) have all been removed.

To post a comment you must log in.
Revision history for this message
Andrew Johnson (anj) wrote :

If nobody has any comments on this branch it will be merged into 3.15 at the Codeathon next week.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'documentation/RELEASE_NOTES.html'
--- documentation/RELEASE_NOTES.html 2010-11-28 03:06:40 +0000
+++ documentation/RELEASE_NOTES.html 2011-02-08 21:39:58 +0000
@@ -13,6 +13,30 @@
13<h2 align="center">Changes between 3.14.x and 3.15.1</h2>13<h2 align="center">Changes between 3.14.x and 3.15.1</h2>
14<!-- Insert new items immediately below here ... -->14<!-- Insert new items immediately below here ... -->
1515
16<h3>
17Reworked the epicsEvent C &amp; C++ APIs</h3>
18
19<ul>
20 <li>Renamed the enum epicsEventWaitStatus to epicsEventStatus</li>
21 <li>Defined epicsEventWaitStatus as a macro for epicsEventStatus</li>
22 <li>Renamed epicsEventWaitOk to epicsEventOk</li>
23 <li>Renamed epicsEventWaitError to epicsEventError</li>
24 <li>Defined epicsEventWaitOK and epicsEventWaitError as macros</li>
25 <li>Added epicsEventTrigger(id) which triggers an event and returns OK or an
26 error status if the underlying OS primitives report an error</li>
27 <li>Added epicsEventMustTrigger(id) which halts on error</li>
28 <li>Defined epicsEventSignal(id) as a macro for epicsEventMustTrigger(id)</li>
29 <li>Added a new C++ method epicsEvent::trigger() which throws an
30 epicsEvent::invalidSemaphore in the event of an error</li>
31 <li>epicsEvent::signal() makes an inline call to epicsEvent::trigger()</li>
32 <li>epicsEventWait() and epicsEventWaitWithTimeout() now return an error
33 status if the underlying OS primitives report an error</li>
34 <li>All the epicsEventMust...() routines are now implemented in the common
35 libCom/osi/epicsEvent.cpp source file, and call cantProceed() instead of
36 mis-using assert()</li>
37 <li>Implemented epicsEventShow() on Posix</li>
38 <li>Win32: Removed all epicsShareAPI decorations</li>
39</ul>
1640
17<h3>41<h3>
18Moved src/RTEMS/base directory</h3>42Moved src/RTEMS/base directory</h3>
1943
=== modified file 'src/libCom/osi/epicsEvent.cpp'
--- src/libCom/osi/epicsEvent.cpp 2004-09-30 19:15:45 +0000
+++ src/libCom/osi/epicsEvent.cpp 2011-02-08 21:39:58 +0000
@@ -1,10 +1,9 @@
1/*************************************************************************\1/*************************************************************************\
2* Copyright (c) 2002 The University of Chicago, as Operator of Argonne2* Copyright (c) 2011 UChicago Argonne LLC, as Operator of Argonne
3* National Laboratory.3* National Laboratory.
4* Copyright (c) 2002 The Regents of the University of California, as4* Copyright (c) 2002 The Regents of the University of California, as
5* Operator of Los Alamos National Laboratory.5* Operator of Los Alamos National Laboratory.
6* EPICS BASE Versions 3.13.76* EPICS BASE is distributed subject to a Software License Agreement found
7* and higher are distributed subject to a Software License Agreement found
8* in file LICENSE that is included with this distribution. 7* in file LICENSE that is included with this distribution.
9\*************************************************************************/8\*************************************************************************/
109
@@ -17,6 +16,7 @@
17#define epicsExportSharedSymbols16#define epicsExportSharedSymbols
18#include "epicsEvent.h"17#include "epicsEvent.h"
19#include "epicsStdioRedirect.h"18#include "epicsStdioRedirect.h"
19#include "cantProceed.h"
2020
21// vxWorks 5.4 gcc fails during compile when I use std::exception21// vxWorks 5.4 gcc fails during compile when I use std::exception
22using namespace std;22using namespace std;
@@ -52,49 +52,81 @@
52 epicsEventDestroy ( this->id );52 epicsEventDestroy ( this->id );
53}53}
5454
55void epicsEvent::signal ()55void epicsEvent::trigger ()
56{56{
57 epicsEventSignal ( this->id );57 epicsEventStatus status = epicsEventTrigger (this->id);
58
59 if (status != epicsEventOK) {
60 throw invalidSemaphore ();
61 }
58}62}
5963
60void epicsEvent::wait ()64void epicsEvent::wait ()
61{65{
62 epicsEventWaitStatus status;66 epicsEventStatus status = epicsEventWait (this->id);
63 status = epicsEventWait (this->id);67
64 if (status!=epicsEventWaitOK) {68 if (status != epicsEventOK) {
65 throw invalidSemaphore ();69 throw invalidSemaphore ();
66 }70 }
67}71}
6872
69bool epicsEvent::wait (double timeOut)73bool epicsEvent::wait (double timeOut)
70{74{
71 epicsEventWaitStatus status;75 epicsEventStatus status = epicsEventWaitWithTimeout (this->id, timeOut);
72 status = epicsEventWaitWithTimeout (this->id, timeOut);76
73 if (status==epicsEventWaitOK) {77 if (status == epicsEventOK) {
74 return true;78 return true;
75 } else if (status==epicsEventWaitTimeout) {79 } else if (status == epicsEventWaitTimeout) {
76 return false;80 return false;
77 } else {
78 throw invalidSemaphore ();
79 }81 }
80 return false;82 throw invalidSemaphore ();
81}83}
8284
83bool epicsEvent::tryWait ()85bool epicsEvent::tryWait ()
84{86{
85 epicsEventWaitStatus status;87 epicsEventStatus status = epicsEventTryWait (this->id);
86 status = epicsEventTryWait (this->id);88
87 if (status==epicsEventWaitOK) {89 if (status == epicsEventOK) {
88 return true;90 return true;
89 } else if (status==epicsEventWaitTimeout) {91 } else if (status == epicsEventWaitTimeout) {
90 return false;92 return false;
91 } else {
92 throw invalidSemaphore ();
93 }93 }
94 return false;94 throw invalidSemaphore ();
95}95}
9696
97void epicsEvent::show ( unsigned level ) const97void epicsEvent::show ( unsigned level ) const
98{98{
99 epicsEventShow ( this->id, level );99 epicsEventShow ( this->id, level );
100}100}
101
102
103// epicsEventMust... convenience routines for C code
104
105extern "C" {
106
107epicsShareFunc epicsEventId epicsEventMustCreate (
108 epicsEventInitialState initialState)
109{
110 epicsEventId id = epicsEventCreate (initialState);
111
112 if (!id)
113 cantProceed ("epicsEventMustCreate");
114 return id;
115}
116
117epicsShareFunc void epicsEventMustTrigger (epicsEventId id) {
118 epicsEventStatus status = epicsEventTrigger (id);
119
120 if (status != epicsEventOK)
121 cantProceed ("epicsEventMustTrigger");
122}
123
124epicsShareFunc void epicsEventMustWait (epicsEventId id) {
125 epicsEventStatus status = epicsEventWait (id);
126
127 if (status != epicsEventOK)
128 cantProceed ("epicsEventMustWait");
129}
130
131} // extern "C"
132
101133
=== modified file 'src/libCom/osi/epicsEvent.h'
--- src/libCom/osi/epicsEvent.h 2009-01-06 17:07:56 +0000
+++ src/libCom/osi/epicsEvent.h 2011-02-08 21:39:58 +0000
@@ -1,25 +1,33 @@
1/*************************************************************************\1/*************************************************************************\
2* Copyright (c) 2002 The University of Chicago, as Operator of Argonne2* Copyright (c) 2011 UChicago Argonne LLC, as Operator of Argonne
3* National Laboratory.3* National Laboratory.
4* Copyright (c) 2002 The Regents of the University of California, as4* Copyright (c) 2002 The Regents of the University of California, as
5* Operator of Los Alamos National Laboratory.5* Operator of Los Alamos National Laboratory.
6* EPICS BASE Versions 3.13.76* EPICS BASE is distributed subject to a Software License Agreement found
7* and higher are distributed subject to a Software License Agreement found
8* in file LICENSE that is included with this distribution. 7* in file LICENSE that is included with this distribution.
9\*************************************************************************/8\*************************************************************************/
10#ifndef epicsEventh9#ifndef epicsEventh
11#define epicsEventh10#define epicsEventh
1211
13#include "epicsAssert.h"
14#include "shareLib.h"12#include "shareLib.h"
1513
16typedef struct epicsEventOSD *epicsEventId;14typedef struct epicsEventOSD *epicsEventId;
1715
18typedef enum {16typedef enum {
19 epicsEventWaitOK,epicsEventWaitTimeout,epicsEventWaitError17 epicsEventOK = 0,
20} epicsEventWaitStatus;18 epicsEventWaitTimeout,
2119 epicsEventError
22typedef enum {epicsEventEmpty,epicsEventFull} epicsEventInitialState;20} epicsEventStatus;
21
22/* Backwards compatibility */
23#define epicsEventWaitStatus epicsEventStatus
24#define epicsEventWaitOK epicsEventOK
25#define epicsEventWaitError epicsEventError
26
27typedef enum {
28 epicsEventEmpty,
29 epicsEventFull
30} epicsEventInitialState;
2331
24#ifdef __cplusplus32#ifdef __cplusplus
2533
@@ -27,42 +35,40 @@
27public:35public:
28 epicsEvent ( epicsEventInitialState initial = epicsEventEmpty );36 epicsEvent ( epicsEventInitialState initial = epicsEventEmpty );
29 ~epicsEvent ();37 ~epicsEvent ();
30 void signal ();38 void trigger ();
31 void wait (); /* blocks until full */39 void signal () { this->trigger(); }
32 bool wait ( double timeOut ); /* false if empty at time out */40 void wait (); /* blocks until full */
33 bool tryWait (); /* false if empty */41 bool wait ( double timeOut ); /* false if still empty at time out */
42 bool tryWait (); /* false if empty */
34 void show ( unsigned level ) const;43 void show ( unsigned level ) const;
3544
36 class invalidSemaphore; /* exception payload */45 class invalidSemaphore; /* exception payload */
37private:46private:
38 epicsEvent ( const epicsEvent & );47 epicsEvent ( const epicsEvent & );
39 epicsEvent & operator = ( const epicsEvent & );48 epicsEvent & operator = ( const epicsEvent & );
40 epicsEventId id;49 epicsEventId id;
41};50};
4251
43#endif /*__cplusplus */
44
45#ifdef __cplusplus
46extern "C" {52extern "C" {
47#endif /*__cplusplus */53#endif /*__cplusplus */
4854
49epicsShareFunc epicsEventId epicsShareAPI epicsEventCreate(55epicsShareFunc epicsEventId epicsEventCreate(
50 epicsEventInitialState initialState);56 epicsEventInitialState initialState);
51epicsShareFunc epicsEventId epicsShareAPI epicsEventMustCreate (57epicsShareFunc epicsEventId epicsEventMustCreate (
52 epicsEventInitialState initialState);58 epicsEventInitialState initialState);
53epicsShareFunc void epicsShareAPI epicsEventDestroy(epicsEventId id);59epicsShareFunc void epicsEventDestroy(epicsEventId id);
54epicsShareFunc void epicsShareAPI epicsEventSignal(epicsEventId id);60epicsShareFunc epicsEventStatus epicsEventTrigger(
55epicsShareFunc epicsEventWaitStatus epicsShareAPI epicsEventWait(61 epicsEventId id);
56 epicsEventId id);62epicsShareFunc void epicsEventMustTrigger(epicsEventId id);
57#define epicsEventMustWait(ID) { \63#define epicsEventSignal(ID) epicsEventMustTrigger(ID)
58 epicsEventWaitStatus status = epicsEventWait(ID); \64epicsShareFunc epicsEventStatus epicsEventWait(
59 assert(status == epicsEventWaitOK); \65 epicsEventId id);
60}66epicsShareFunc void epicsEventMustWait(epicsEventId id);
61epicsShareFunc epicsEventWaitStatus epicsShareAPI epicsEventWaitWithTimeout(67epicsShareFunc epicsEventStatus epicsEventWaitWithTimeout(
62 epicsEventId id, double timeOut);68 epicsEventId id, double timeOut);
63epicsShareFunc epicsEventWaitStatus epicsShareAPI epicsEventTryWait(69epicsShareFunc epicsEventStatus epicsEventTryWait(
64 epicsEventId id);70 epicsEventId id);
65epicsShareFunc void epicsShareAPI epicsEventShow(71epicsShareFunc void epicsEventShow(
66 epicsEventId id, unsigned int level);72 epicsEventId id, unsigned int level);
6773
68#ifdef __cplusplus74#ifdef __cplusplus
6975
=== modified file 'src/libCom/osi/os/RTEMS/osdEvent.c'
--- src/libCom/osi/os/RTEMS/osdEvent.c 2010-10-05 19:27:37 +0000
+++ src/libCom/osi/os/RTEMS/osdEvent.c 2011-02-08 21:39:58 +0000
@@ -1,7 +1,8 @@
1/*************************************************************************\1/*************************************************************************\
2* Copyright (c) 2002 The University of Saskatchewan2* Copyright (c) 2002 The University of Saskatchewan
3* EPICS BASE Versions 3.13.73* Copyright (c) 2011 UChicago Argonne LLC, as Operator of Argonne
4* and higher are distributed subject to a Software License Agreement found4* National Laboratory.
5* EPICS BASE is distributed subject to a Software License Agreement found
5* in file LICENSE that is included with this distribution. 6* in file LICENSE that is included with this distribution.
6\*************************************************************************/7\*************************************************************************/
7/*8/*
@@ -18,7 +19,6 @@
18 */19 */
19#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ 120#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ 1
2021
21#include <assert.h>
22#include <stdio.h>22#include <stdio.h>
23#include <rtems.h>23#include <rtems.h>
24#include <rtems/error.h>24#include <rtems/error.h>
@@ -84,13 +84,6 @@
84 return (epicsEventId)sid;84 return (epicsEventId)sid;
85}85}
8686
87epicsEventId epicsEventMustCreate(epicsEventInitialState initialState)
88{
89 epicsEventId id = epicsEventCreate (initialState);
90 assert (id);
91 return id;
92}
93
94void87void
95epicsEventDestroy(epicsEventId id)88epicsEventDestroy(epicsEventId id)
96{89{
@@ -102,18 +95,20 @@
102 errlogPrintf ("Can't destroy semaphore: %s\n", rtems_status_text (sc));95 errlogPrintf ("Can't destroy semaphore: %s\n", rtems_status_text (sc));
103}96}
10497
105void98epicsEventStatus
106epicsEventSignal(epicsEventId id)99epicsEventTrigger(epicsEventId id)
107{100{
108 rtems_id sid = (rtems_id)id;101 rtems_id sid = (rtems_id)id;
109 rtems_status_code sc;102 rtems_status_code sc;
110 103
111 sc = rtems_semaphore_release (sid);104 sc = rtems_semaphore_release (sid);
112 if (sc != RTEMS_SUCCESSFUL)105 if (sc == RTEMS_SUCCESSFUL)
113 errlogPrintf ("Can't release semaphore: %s\n", rtems_status_text (sc));106 return epicsEventOK;
107 errlogPrintf ("Can't release semaphore: %s\n", rtems_status_text (sc));
108 return epicsEventError;
114}109}
115110
116epicsEventWaitStatus111epicsEventStatus
117epicsEventWait(epicsEventId id)112epicsEventWait(epicsEventId id)
118{113{
119 rtems_id sid = (rtems_id)id;114 rtems_id sid = (rtems_id)id;
@@ -122,11 +117,11 @@
122 SEMSTAT(0)117 SEMSTAT(0)
123 sc = rtems_semaphore_obtain (sid, RTEMS_WAIT, RTEMS_NO_TIMEOUT);118 sc = rtems_semaphore_obtain (sid, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
124 if (sc != RTEMS_SUCCESSFUL)119 if (sc != RTEMS_SUCCESSFUL)
125 return epicsEventWaitError;120 return epicsEventError;
126 return epicsEventWaitOK;121 return epicsEventOK;
127}122}
128123
129epicsEventWaitStatus124epicsEventStatus
130epicsEventWaitWithTimeout(epicsEventId id, double timeOut)125epicsEventWaitWithTimeout(epicsEventId id, double timeOut)
131{126{
132 rtems_id sid = (rtems_id)id;127 rtems_id sid = (rtems_id)id;
@@ -142,14 +137,14 @@
142 delay++;137 delay++;
143 sc = rtems_semaphore_obtain (sid, RTEMS_WAIT, delay);138 sc = rtems_semaphore_obtain (sid, RTEMS_WAIT, delay);
144 if (sc == RTEMS_SUCCESSFUL)139 if (sc == RTEMS_SUCCESSFUL)
145 return epicsEventWaitOK;140 return epicsEventOK;
146 else if (sc == RTEMS_TIMEOUT)141 else if (sc == RTEMS_TIMEOUT)
147 return epicsEventWaitTimeout;142 return epicsEventWaitTimeout;
148 else143 else
149 return epicsEventWaitError;144 return epicsEventError;
150}145}
151146
152epicsEventWaitStatus147epicsEventStatus
153epicsEventTryWait(epicsEventId id)148epicsEventTryWait(epicsEventId id)
154{149{
155 rtems_id sid = (rtems_id)id;150 rtems_id sid = (rtems_id)id;
@@ -158,11 +153,11 @@
158 SEMSTAT(2)153 SEMSTAT(2)
159 sc = rtems_semaphore_obtain (sid, RTEMS_NO_WAIT, RTEMS_NO_TIMEOUT);154 sc = rtems_semaphore_obtain (sid, RTEMS_NO_WAIT, RTEMS_NO_TIMEOUT);
160 if (sc == RTEMS_SUCCESSFUL)155 if (sc == RTEMS_SUCCESSFUL)
161 return epicsEventWaitOK;156 return epicsEventOK;
162 else if (sc == RTEMS_UNSATISFIED)157 else if (sc == RTEMS_UNSATISFIED)
163 return epicsEventWaitTimeout;158 return epicsEventWaitTimeout;
164 else159 else
165 return epicsEventWaitError;160 return epicsEventError;
166}161}
167162
168void163void
169164
=== modified file 'src/libCom/osi/os/WIN32/osdEvent.c'
--- src/libCom/osi/os/WIN32/osdEvent.c 2010-10-05 19:27:37 +0000
+++ src/libCom/osi/os/WIN32/osdEvent.c 2011-02-08 21:39:58 +0000
@@ -1,10 +1,9 @@
1/*************************************************************************\1/*************************************************************************\
2* Copyright (c) 2002 The University of Chicago, as Operator of Argonne2* Copyright (c) 2011 UChicago Argonne LLC, as Operator of Argonne
3* National Laboratory.3* National Laboratory.
4* Copyright (c) 2002 The Regents of the University of California, as4* Copyright (c) 2002 The Regents of the University of California, as
5* Operator of Los Alamos National Laboratory.5* Operator of Los Alamos National Laboratory.
6* EPICS BASE Versions 3.13.76* EPICS BASE is distributed subject to a Software License Agreement found
7* and higher are distributed subject to a Software License Agreement found
8* in file LICENSE that is included with this distribution. 7* in file LICENSE that is included with this distribution.
9\*************************************************************************/8\*************************************************************************/
10/* osdEvent.c */9/* osdEvent.c */
@@ -27,7 +26,6 @@
27#define epicsExportSharedSymbols26#define epicsExportSharedSymbols
28#include "shareLib.h"27#include "shareLib.h"
29#include "epicsEvent.h"28#include "epicsEvent.h"
30#include "epicsAssert.h"
3129
32typedef struct epicsEventOSD {30typedef struct epicsEventOSD {
33 HANDLE handle;31 HANDLE handle;
@@ -36,7 +34,7 @@
36/*34/*
37 * epicsEventCreate ()35 * epicsEventCreate ()
38 */36 */
39epicsShareFunc epicsEventId epicsShareAPI epicsEventCreate (37epicsShareFunc epicsEventId epicsEventCreate (
40 epicsEventInitialState initialState ) 38 epicsEventInitialState initialState )
41{39{
42 epicsEventOSD *pSem;40 epicsEventOSD *pSem;
@@ -54,54 +52,43 @@
54}52}
5553
56/*54/*
57 * epicsEventMustCreate ()
58 */
59epicsShareFunc epicsEventId epicsShareAPI epicsEventMustCreate (
60 epicsEventInitialState initialState )
61{
62 epicsEventId id = epicsEventCreate ( initialState );
63 assert ( id );
64 return id;
65}
66
67/*
68 * epicsEventDestroy ()55 * epicsEventDestroy ()
69 */56 */
70epicsShareFunc void epicsShareAPI epicsEventDestroy ( epicsEventId pSem ) 57epicsShareFunc void epicsEventDestroy ( epicsEventId pSem )
71{58{
72 CloseHandle ( pSem->handle );59 CloseHandle ( pSem->handle );
73 free ( pSem );60 free ( pSem );
74}61}
7562
76/*63/*
77 * epicsEventSignal ()64 * epicsEventTrigger ()
78 */65 */
79epicsShareFunc void epicsShareAPI epicsEventSignal ( epicsEventId pSem ) 66epicsShareFunc epicsEventStatus epicsEventTrigger ( epicsEventId pSem )
80{67{
81 BOOL status;68 BOOL status;
82 status = SetEvent ( pSem->handle );69 status = SetEvent ( pSem->handle );
83 assert ( status ); 70 return status ? epicsEventOK : epicsEventError;
84}71}
8572
86/*73/*
87 * epicsEventWait ()74 * epicsEventWait ()
88 */75 */
89epicsShareFunc epicsEventWaitStatus epicsShareAPI epicsEventWait ( epicsEventId pSem ) 76epicsShareFunc epicsEventStatus epicsEventWait ( epicsEventId pSem )
90{ 77{
91 DWORD status;78 DWORD status;
92 status = WaitForSingleObject (pSem->handle, INFINITE);79 status = WaitForSingleObject (pSem->handle, INFINITE);
93 if ( status == WAIT_OBJECT_0 ) {80 if ( status == WAIT_OBJECT_0 ) {
94 return epicsEventWaitOK;81 return epicsEventOK;
95 }82 }
96 else {83 else {
97 return epicsEventWaitError;84 return epicsEventError;
98 }85 }
99}86}
10087
101/*88/*
102 * epicsEventWaitWithTimeout ()89 * epicsEventWaitWithTimeout ()
103 */90 */
104epicsShareFunc epicsEventWaitStatus epicsShareAPI epicsEventWaitWithTimeout (91epicsShareFunc epicsEventStatus epicsEventWaitWithTimeout (
105 epicsEventId pSem, double timeOut )92 epicsEventId pSem, double timeOut )
106{ 93{
107 static const unsigned mSecPerSec = 1000;94 static const unsigned mSecPerSec = 1000;
@@ -122,38 +109,38 @@
122 }109 }
123 status = WaitForSingleObject ( pSem->handle, tmo );110 status = WaitForSingleObject ( pSem->handle, tmo );
124 if ( status == WAIT_OBJECT_0 ) {111 if ( status == WAIT_OBJECT_0 ) {
125 return epicsEventWaitOK;112 return epicsEventOK;
126 }113 }
127 else if ( status == WAIT_TIMEOUT ) {114 else if ( status == WAIT_TIMEOUT ) {
128 return epicsEventWaitTimeout;115 return epicsEventWaitTimeout;
129 }116 }
130 else {117 else {
131 return epicsEventWaitError;118 return epicsEventError;
132 }119 }
133}120}
134121
135/*122/*
136 * epicsEventTryWait ()123 * epicsEventTryWait ()
137 */124 */
138epicsShareFunc epicsEventWaitStatus epicsShareAPI epicsEventTryWait ( epicsEventId pSem ) 125epicsShareFunc epicsEventStatus epicsEventTryWait ( epicsEventId pSem )
139{ 126{
140 DWORD status;127 DWORD status;
141128
142 status = WaitForSingleObject ( pSem->handle, 0 );129 status = WaitForSingleObject ( pSem->handle, 0 );
143 if ( status == WAIT_OBJECT_0 ) {130 if ( status == WAIT_OBJECT_0 ) {
144 return epicsEventWaitOK;131 return epicsEventOK;
145 }132 }
146 else if ( status == WAIT_TIMEOUT ) {133 else if ( status == WAIT_TIMEOUT ) {
147 return epicsEventWaitTimeout;134 return epicsEventWaitTimeout;
148 }135 }
149 else {136 else {
150 return epicsEventWaitError;137 return epicsEventError;
151 }138 }
152}139}
153140
154/*141/*
155 * epicsEventShow ()142 * epicsEventShow ()
156 */143 */
157epicsShareFunc void epicsShareAPI epicsEventShow ( epicsEventId id, unsigned level ) 144epicsShareFunc void epicsEventShow ( epicsEventId id, unsigned level )
158{ 145{
159}146}
160147
=== modified file 'src/libCom/osi/os/posix/osdEvent.c'
--- src/libCom/osi/os/posix/osdEvent.c 2009-04-23 18:49:40 +0000
+++ src/libCom/osi/os/posix/osdEvent.c 2011-02-08 21:39:58 +0000
@@ -1,5 +1,5 @@
1/*************************************************************************\1/*************************************************************************\
2* Copyright (c) 2009 UChicago Argonne LLC, as Operator of Argonne2* Copyright (c) 2011 UChicago Argonne LLC, as Operator of Argonne
3* National Laboratory.3* National Laboratory.
4* Copyright (c) 2002 The Regents of the University of California, as4* Copyright (c) 2002 The Regents of the University of California, as
5* Operator of Los Alamos National Laboratory.5* Operator of Los Alamos National Laboratory.
@@ -21,155 +21,142 @@
2121
22#define epicsExportSharedSymbols22#define epicsExportSharedSymbols
23#include "epicsEvent.h"23#include "epicsEvent.h"
24#include "cantProceed.h"
25#include "epicsTime.h"24#include "epicsTime.h"
26#include "errlog.h"25#include "errlog.h"
27#include "epicsAssert.h"
2826
29/* Until these can be demonstrated to work leave them undefined*/27/* Until these can be demonstrated to work leave them undefined*/
30#undef _POSIX_THREAD_PROCESS_SHARED28#undef _POSIX_THREAD_PROCESS_SHARED
31#undef _POSIX_THREAD_PRIO_INHERIT29#undef _POSIX_THREAD_PRIO_INHERIT
3230
33typedef struct epicsEventOSD {
34 pthread_mutex_t mutex;
35 pthread_cond_t cond;
36 int isFull;
37}epicsEventOSD;
38
3931
40#define checkStatus(status,message) \
41if((status)) { \
42 errlogPrintf("epicsEvent %s failed: error %s\n",(message),strerror((status)));}
43
44#define checkStatusQuit(status,message,method) \
45if(status) { \
46 errlogPrintf("epicsEvent %s failed: error %s\n",(message),strerror((status))); \
47 cantProceed((method)); \
48}
49
50static int mutexLock(pthread_mutex_t *id)
51{
52 int status;
53
54 while(1) {
55 status = pthread_mutex_lock(id);
56 if(status!=EINTR) return status;
57 errlogPrintf("pthread_mutex_lock returned EINTR. Violates SUSv3\n");
58 }
59}
60
61static int condTimedwait(pthread_cond_t *condId, pthread_mutex_t *mutexId,
62 struct timespec *time)
63{
64 int status;
65 while(1) {
66 status = pthread_cond_timedwait(condId,mutexId,time);
67 if(status!=EINTR) return status;
68 errlogPrintf("pthread_cond_timedwait returned EINTR. Violates SUSv3\n");
69 }
70}
71
72static int condWait(pthread_cond_t *condId, pthread_mutex_t *mutexId)
73{
74 int status;
75 while(1) {
76 status = pthread_cond_wait(condId,mutexId);
77 if(status!=EINTR) return status;
78 errlogPrintf("pthread_cond_wait returned EINTR. Violates SUSv3\n");
79 }
80}
81
8232
83epicsShareFunc epicsEventId epicsShareAPI epicsEventCreate(epicsEventInitialState initialState)33struct epicsEventOSD {
84{34 pthread_mutex_t mutex;
85 epicsEventOSD *pevent;35 pthread_cond_t cond;
86 int status;36 int isFull;
8737};
88 pevent = callocMustSucceed(1,sizeof(*pevent),"epicsEventCreate");38
89 status = pthread_mutex_init(&pevent->mutex,0);39#define printStatus(status, routine, func) \
90 checkStatusQuit(status,"pthread_mutex_init","epicsEventCreate");40 errlogPrintf("%s: %s failed: %s\n", (func), (routine), strerror(status))
91 status = pthread_cond_init(&pevent->cond,0);41
92 checkStatusQuit(status,"pthread_cond_init","epicsEventCreate");42#define checkStatus(status, routine, func) \
93 if(initialState==epicsEventFull) pevent->isFull = 1;43 if (status) { \
94 return((epicsEventId)pevent);44 printStatus(status, routine, func); \
95}45 }
9646
97epicsShareFunc epicsEventId epicsShareAPI epicsEventMustCreate(epicsEventInitialState initialState)47#define checkStatusReturn(status, routine, func) \
98{48 if (status) { \
99 epicsEventId id = epicsEventCreate (initialState);49 printStatus(status, routine, func); \
100 assert (id);50 return epicsEventError; \
101 return id;51 }
102}52
10353
104epicsShareFunc void epicsShareAPI epicsEventDestroy(epicsEventId pevent)54epicsShareFunc epicsEventId epicsEventCreate(epicsEventInitialState init)
105{55{
106 int status;56 epicsEventId pevent = malloc(sizeof(*pevent));
10757
108 status = pthread_mutex_destroy(&pevent->mutex);58 if (pevent) {
109 checkStatus(status,"pthread_mutex_destroy");59 int status = pthread_mutex_init(&pevent->mutex, 0);
60
61 pevent->isFull = (init == epicsEventFull);
62 if (status) {
63 printStatus(status, "pthread_mutex_init", "epicsEventCreate");
64 } else {
65 status = pthread_cond_init(&pevent->cond, 0);
66 if (!status)
67 return pevent;
68 printStatus(status, "pthread_cond_init", "epicsEventCreate");
69 status = pthread_mutex_destroy(&pevent->mutex);
70 checkStatus(status, "pthread_mutex_destroy", "epicsEventCreate");
71 }
72 free(pevent);
73 }
74 return NULL;
75}
76
77epicsShareFunc void epicsEventDestroy(epicsEventId pevent)
78{
79 int status = pthread_mutex_destroy(&pevent->mutex);
80
81 checkStatus(status, "pthread_mutex_destroy", "epicsEventDestroy");
110 status = pthread_cond_destroy(&pevent->cond);82 status = pthread_cond_destroy(&pevent->cond);
111 checkStatus(status,"pthread_cond_destroy");83 checkStatus(status, "pthread_cond_destroy", "epicsEventDestroy");
112 free(pevent);84 free(pevent);
113}85}
11486
115epicsShareFunc void epicsShareAPI epicsEventSignal(epicsEventId pevent)87epicsShareFunc epicsEventStatus epicsEventTrigger(epicsEventId pevent)
116{88{
117 int status;89 int status = pthread_mutex_lock(&pevent->mutex);
11890
119 status = mutexLock(&pevent->mutex);91 checkStatusReturn(status, "pthread_mutex_lock", "epicsEventTrigger");
120 checkStatusQuit(status,"pthread_mutex_lock","epicsEventSignal");92 if (!pevent->isFull) {
121 if(!pevent->isFull) {
122 pevent->isFull = 1;93 pevent->isFull = 1;
123 status = pthread_cond_signal(&pevent->cond);94 status = pthread_cond_signal(&pevent->cond);
124 checkStatus(status,"pthread_cond_signal");
125 }
126 status = pthread_mutex_unlock(&pevent->mutex);
127 checkStatusQuit(status,"pthread_mutex_unlock","epicsEventSignal");
128}
129
13095
131epicsShareFunc epicsEventWaitStatus epicsShareAPI epicsEventWait(epicsEventId pevent)96 checkStatus(status, "pthread_cond_signal", "epicsEventTrigger");
132{97 }
133 int status;98 status = pthread_mutex_unlock(&pevent->mutex);
13499 checkStatusReturn(status, "pthread_mutex_unlock", "epicsEventTrigger");
135 if(!pevent) return(epicsEventWaitError);100 return epicsEventOK;
136 status = mutexLock(&pevent->mutex);101}
137 checkStatusQuit(status,"pthread_mutex_lock","epicsEventWait");102
138 /*no need for while since caller must be prepared for no work*/103epicsShareFunc epicsEventStatus epicsEventWait(epicsEventId pevent)
139 if(!pevent->isFull) {104{
140 status = condWait(&pevent->cond,&pevent->mutex);105 epicsEventStatus result = epicsEventOK;
141 checkStatusQuit(status,"pthread_cond_wait","epicsEventWait");106 int status = pthread_mutex_lock(&pevent->mutex);
142 }107
143 pevent->isFull = 0;108 checkStatusReturn(status, "pthread_mutex_lock", "epicsEventWait");
144 status = pthread_mutex_unlock(&pevent->mutex);109 while (!pevent->isFull) {
145 checkStatusQuit(status,"pthread_mutex_unlock","epicsEventWait");110 status = pthread_cond_wait(&pevent->cond, &pevent->mutex);
146 return(epicsEventWaitOK);111 if (status) {
147}112 printStatus(status, "pthread_cond_wait", "epicsEventWait");
148113 result = epicsEventError;
149epicsShareFunc epicsEventWaitStatus epicsShareAPI epicsEventWaitWithTimeout(epicsEventId pevent, double timeout)114 goto release;
150{115 }
151 struct timespec wakeTime;116 }
152 int status = 0;117 pevent->isFull = 0;
153 int unlockStatus;118 result = epicsEventOK;
154119release:
155 status = mutexLock(&pevent->mutex);120 status = pthread_mutex_unlock(&pevent->mutex);
156 checkStatusQuit(status,"pthread_mutex_lock","epicsEventWaitWithTimeout");121 checkStatusReturn(status, "pthread_mutex_unlock", "epicsEventWait");
157 if(!pevent->isFull) {122 return result;
158 convertDoubleToWakeTime(timeout,&wakeTime);123}
159 status = condTimedwait(124
160 &pevent->cond,&pevent->mutex,&wakeTime);125epicsShareFunc epicsEventStatus epicsEventWaitWithTimeout(epicsEventId pevent,
161 }126 double timeout)
162 if(status==0) pevent->isFull = 0;127{
163 unlockStatus = pthread_mutex_unlock(&pevent->mutex);128 epicsEventStatus result = epicsEventOK;
164 checkStatusQuit(unlockStatus,"pthread_mutex_unlock","epicsEventWaitWithTimeout");129 int status = pthread_mutex_lock(&pevent->mutex);
165 if(status==0) return(epicsEventWaitOK);130
166 if(status==ETIMEDOUT) return(epicsEventWaitTimeout);131 checkStatusReturn(status, "pthread_mutex_lock", "epicsEventWaitWithTimeout");
167 checkStatus(status,"pthread_cond_timedwait");132 if (!pevent->isFull) {
168 return(epicsEventWaitError);133 struct timespec wakeTime;
169}134
170135 convertDoubleToWakeTime(timeout, &wakeTime);
171epicsShareFunc epicsEventWaitStatus epicsShareAPI epicsEventTryWait(epicsEventId id)136 while (!status && !pevent->isFull) {
172{137 status = pthread_cond_timedwait(&pevent->cond, &pevent->mutex,
173 return(epicsEventWaitWithTimeout(id,0.0));138 &wakeTime);
174}139 }
175140 if (status) {
176epicsShareFunc void epicsShareAPI epicsEventShow(epicsEventId id,unsigned int level)141 result = (status == ETIMEDOUT) ?
177{142 epicsEventWaitTimeout : epicsEventError;
143 goto release;
144 }
145 }
146 pevent->isFull = 0;
147release:
148 status = pthread_mutex_unlock(&pevent->mutex);
149 checkStatusReturn(status, "pthread_mutex_unlock", "epicsEventWaitWithTimeout");
150 return result;
151}
152
153epicsShareFunc epicsEventStatus epicsEventTryWait(epicsEventId id)
154{
155 return epicsEventWaitWithTimeout(id, 0.0);
156}
157
158epicsShareFunc void epicsEventShow(epicsEventId pevent, unsigned int level)
159{
160 printf("epicsEvent %p: %s\n", pevent,
161 pevent->isFull ? "full" : "empty");
162 if (level > 0)
163 printf(" pthread_mutex = %p, pthread_cond = %p\n",
164 &pevent->mutex, &pevent->cond);
178}165}
179166
=== modified file 'src/libCom/osi/os/vxWorks/osdEvent.c'
--- src/libCom/osi/os/vxWorks/osdEvent.c 2008-09-24 19:24:59 +0000
+++ src/libCom/osi/os/vxWorks/osdEvent.c 2011-02-08 21:39:58 +0000
@@ -1,10 +1,9 @@
1/*************************************************************************\1/*************************************************************************\
2* Copyright (c) 2002 The University of Chicago, as Operator of Argonne2* Copyright (c) 2011 UChicago Argonne LLC, as Operator of Argonne
3* National Laboratory.3* National Laboratory.
4* Copyright (c) 2002 The Regents of the University of California, as4* Copyright (c) 2002 The Regents of the University of California, as
5* Operator of Los Alamos National Laboratory.5* Operator of Los Alamos National Laboratory.
6* EPICS BASE Versions 3.13.76* EPICS BASE is distributed subject to a Software License Agreement found
7* and higher are distributed subject to a Software License Agreement found
8* in file LICENSE that is included with this distribution. 7* in file LICENSE that is included with this distribution.
9\*************************************************************************/8\*************************************************************************/
10/* os/vxWorks/osdEvent.c */9/* os/vxWorks/osdEvent.c */
@@ -29,19 +28,12 @@
29 (initialState == epicsEventEmpty) ? SEM_EMPTY : SEM_FULL);28 (initialState == epicsEventEmpty) ? SEM_EMPTY : SEM_FULL);
30}29}
3130
32epicsEventId epicsEventMustCreate(epicsEventInitialState initialState)
33{
34 epicsEventId id = epicsEventCreate(initialState);
35 assert(id);
36 return id;
37}
38
39void epicsEventDestroy(epicsEventId id)31void epicsEventDestroy(epicsEventId id)
40{32{
41 semDelete((SEM_ID)id);33 semDelete((SEM_ID)id);
42}34}
4335
44epicsEventWaitStatus epicsEventWaitWithTimeout(epicsEventId id, double timeOut)36epicsEventStatus epicsEventWaitWithTimeout(epicsEventId id, double timeOut)
45{37{
46 int rate = sysClkRateGet();38 int rate = sysClkRateGet();
47 int status;39 int status;
@@ -58,22 +50,22 @@
58 }50 }
59 status = semTake((SEM_ID)id, ticks);51 status = semTake((SEM_ID)id, ticks);
60 if (status == OK)52 if (status == OK)
61 return epicsEventWaitOK;53 return epicsEventOK;
62 if (errno == S_objLib_OBJ_TIMEOUT ||54 if (errno == S_objLib_OBJ_TIMEOUT ||
63 (errno == S_objLib_OBJ_UNAVAILABLE && ticks == 0))55 (errno == S_objLib_OBJ_UNAVAILABLE && ticks == 0))
64 return epicsEventWaitTimeout;56 return epicsEventWaitTimeout;
65 return epicsEventWaitError;57 return epicsEventError;
66}58}
6759
68epicsEventWaitStatus epicsEventTryWait(epicsEventId id)60epicsEventStatus epicsEventTryWait(epicsEventId id)
69{61{
70 int status = semTake((SEM_ID)id, NO_WAIT);62 int status = semTake((SEM_ID)id, NO_WAIT);
7163
72 if (status == OK)64 if (status == OK)
73 return epicsEventWaitOK;65 return epicsEventOK;
74 if (errno == S_objLib_OBJ_UNAVAILABLE)66 if (errno == S_objLib_OBJ_UNAVAILABLE)
75 return epicsEventWaitTimeout;67 return epicsEventWaitTimeout;
76 return epicsEventWaitError;68 return epicsEventError;
77}69}
7870
79void epicsEventShow(epicsEventId id, unsigned int level)71void epicsEventShow(epicsEventId id, unsigned int level)
8072
=== modified file 'src/libCom/osi/os/vxWorks/osdEvent.h'
--- src/libCom/osi/os/vxWorks/osdEvent.h 2002-07-12 21:35:43 +0000
+++ src/libCom/osi/os/vxWorks/osdEvent.h 2011-02-08 21:39:58 +0000
@@ -1,10 +1,9 @@
1/*************************************************************************\1/*************************************************************************\
2* Copyright (c) 2002 The University of Chicago, as Operator of Argonne2* Copyright (c) 2011 UChicago Argonne LLC, as Operator of Argonne
3* National Laboratory.3* National Laboratory.
4* Copyright (c) 2002 The Regents of the University of California, as4* Copyright (c) 2002 The Regents of the University of California, as
5* Operator of Los Alamos National Laboratory.5* Operator of Los Alamos National Laboratory.
6* EPICS BASE Versions 3.13.76* EPICS BASE is distributed subject to a Software License Agreement found
7* and higher are distributed subject to a Software License Agreement found
8* in file LICENSE that is included with this distribution. 7* in file LICENSE that is included with this distribution.
9\*************************************************************************/8\*************************************************************************/
10/* os/vxWorks/osdEvent.h */9/* os/vxWorks/osdEvent.h */
@@ -14,12 +13,8 @@
14#include <vxWorks.h>13#include <vxWorks.h>
15#include <semLib.h>14#include <semLib.h>
1615
17/* If the macro is replaced by inline it is necessary to say16#define epicsEventTrigger(ID) \
18 static __inline__17 (semGive((SEM_ID)(ID)) == OK ? epicsEventOK : epicsEventError)
19 but then a warning message appears everywhere osdEvent.h is included
20*/
21
22#define epicsEventSignal(ID) semGive((SEM_ID)(ID))
2318
24#define epicsEventWait(ID) \19#define epicsEventWait(ID) \
25(semTake((SEM_ID)(ID),WAIT_FOREVER)==OK ? epicsEventWaitOK : epicsEventWaitError)20 (semTake((SEM_ID)(ID), WAIT_FOREVER) == OK ? epicsEventOK : epicsEventError)

Subscribers

People subscribed via source and target branches