libCom: timerQueueActive atomic exitFlag

quiet false positive data race
This commit is contained in:
Michael Davidsaver
2017-11-08 10:07:55 -06:00
parent c1ab30142a
commit 6ce8dfec01
2 changed files with 7 additions and 6 deletions

View File

@@ -147,7 +147,7 @@ private:
epicsThread thread;
const double sleepQuantum;
bool okToShare;
bool exitFlag;
int exitFlag; // use atomic ops
bool terminateFlag;
void run ();
void reschedule ();

View File

@@ -15,6 +15,7 @@
#include <stdio.h>
#define epicsExportSharedSymbols
#include "epicsAtomic.h"
#include "timerPrivate.h"
#include "errlog.h"
@@ -46,7 +47,7 @@ timerQueueActive ::
_refMgr ( refMgr ), queue ( *this ), thread ( *this, "timerQueue",
epicsThreadGetStackSize ( epicsThreadStackMedium ), priority ),
sleepQuantum ( epicsThreadSleepQuantum() ), okToShare ( okToShareIn ),
exitFlag ( false ), terminateFlag ( false )
exitFlag ( 0 ), terminateFlag ( false )
{
}
@@ -59,7 +60,7 @@ timerQueueActive::~timerQueueActive ()
{
this->terminateFlag = true;
this->rescheduleEvent.signal ();
while ( ! this->exitFlag ) {
while ( ! epics::atomic::get(this->exitFlag) ) {
this->exitEvent.wait ( 1.0 );
}
// in case other threads are waiting here also
@@ -87,7 +88,7 @@ void timerQueueActive :: _printLastChanceExceptionMessage (
void timerQueueActive :: run ()
{
this->exitFlag = false;
epics::atomic::set(this->exitFlag, 0);
while ( ! this->terminateFlag ) {
try {
double delay = this->queue.process ( epicsTime::getCurrent() );
@@ -105,7 +106,7 @@ void timerQueueActive :: run ()
epicsThreadSleep ( 10.0 );
}
}
this->exitFlag = true;
epics::atomic::set(this->exitFlag, 1);
this->exitEvent.signal (); // no access to queue after exitEvent signal
}
@@ -143,7 +144,7 @@ void timerQueueActive::show ( unsigned int level ) const
printf ( "exit event\n" );
this->exitEvent.show ( level - 1u );
printf ( "exitFlag = %c, terminateFlag = %c\n",
this->exitFlag ? 'T' : 'F',
epics::atomic::get(this->exitFlag) ? 'T' : 'F',
this->terminateFlag ? 'T' : 'F' );
}
}