Merge ~epics-core/epics-base/+git/fixups:db_close_events into ~epics-core/epics-base/+git/epics-base:3.15

Proposed by mdavidsaver
Status: Merged
Merged at revision: 0f0deb8903aa879aecdd8f6b624b376ea7cf86e1
Proposed branch: ~epics-core/epics-base/+git/fixups:db_close_events
Merge into: ~epics-core/epics-base/+git/epics-base:3.15
Diff against target: 64 lines (+19/-0)
1 file modified
src/ioc/db/dbEvent.c (+19/-0)
Reviewer Review Type Date Requested Status
Andrew Johnson Approve
Review via email: mp+333415@code.launchpad.net

Description of the change

Fix for lp:1730982. Use a global lock to ensure the event isn't destroy'd before the worker has returned from epicsEventSignal().

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

Merging, assumed to be correct since I can only check that it doesn't break anything.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/ioc/db/dbEvent.c b/src/ioc/db/dbEvent.c
2index 5e386dd..fb1f3a1 100644
3--- a/src/ioc/db/dbEvent.c
4+++ b/src/ioc/db/dbEvent.c
5@@ -117,6 +117,8 @@ static char *EVENT_PEND_NAME = "eventTask";
6
7 static struct evSubscrip canceledEvent;
8
9+static epicsMutexId stopSync;
10+
11 static unsigned short ringSpace ( const struct event_que *pevq )
12 {
13 if ( pevq->evque[pevq->putix] == EVENTQEMPTY ) {
14@@ -258,6 +260,10 @@ dbEventCtx db_init_events (void)
15 {
16 struct event_user * evUser;
17
18+ if (!stopSync) {
19+ stopSync = epicsMutexMustCreate();
20+ }
21+
22 if (!dbevEventUserFreeList) {
23 freeListInitPvt(&dbevEventUserFreeList,
24 sizeof(struct event_user),8);
25@@ -321,6 +327,8 @@ fail:
26 return NULL;
27 }
28
29+
30+ /* intentionally leak stopSync to avoid possible shutdown races */
31 /*
32 * DB_CLOSE_EVENTS()
33 *
34@@ -356,11 +364,15 @@ void db_close_events (dbEventCtx ctx)
35
36 epicsMutexUnlock ( evUser->lock );
37
38+ epicsMutexMustLock (stopSync);
39+
40 epicsEventDestroy(evUser->pexitsem);
41 epicsEventDestroy(evUser->ppendsem);
42 epicsEventDestroy(evUser->pflush_sem);
43 epicsMutexDestroy(evUser->lock);
44
45+ epicsMutexUnlock (stopSync);
46+
47 freeListFree(dbevEventUserFreeList, evUser);
48 }
49
50@@ -1043,8 +1055,15 @@ static void event_task (void *pParm)
51
52 taskwdRemove(epicsThreadGetIdSelf());
53
54+ /* use stopSync to ensure pexitsem is not destroy'd
55+ * until epicsEventSignal() has returned.
56+ */
57+ epicsMutexMustLock (stopSync);
58+
59 epicsEventSignal(evUser->pexitsem);
60
61+ epicsMutexUnlock(stopSync);
62+
63 return;
64 }
65

Subscribers

People subscribed via source and target branches