From a23fd62d40fa7553ff6b96c9a36a5fb92af0837d Mon Sep 17 00:00:00 2001 From: MarkRivers Date: Sun, 3 Apr 2011 19:01:06 +0000 Subject: [PATCH] Added epicsAtExit logic to stop polling when shutting down --- motorApp/NewportSrc/XPSAxis.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/motorApp/NewportSrc/XPSAxis.cpp b/motorApp/NewportSrc/XPSAxis.cpp index 30415187..4e02f4a1 100644 --- a/motorApp/NewportSrc/XPSAxis.cpp +++ b/motorApp/NewportSrc/XPSAxis.cpp @@ -87,6 +87,7 @@ Versions: Release 4-5 and higher. #include #include #include +#include #include #include @@ -135,8 +136,16 @@ static double setPosSleepTime = 0.5; #define MAX(a,b) ((a)>(b)? (a): (b)) #define MIN(a,b) ((a)<(b)? (a): (b)) -// These are the XPSAxis:: methods +extern "C" void shutdownCallback(void *pPvt) +{ + XPSController *pC = static_cast(pPvt); + pC->lock(); + pC->shuttingDown_ = 1; + pC->unlock(); +} + +// These are the XPSAxis:: methods XPSAxis::XPSAxis(XPSController *pC, int axisNo, const char *positionerName, double stepSize) : asynMotorAxis(pC, axisNo), pC_(pC) @@ -154,6 +163,9 @@ XPSAxis::XPSAxis(XPSController *pC, int axisNo, const char *positionerName, doub /* Set the poll rate on the moveSocket to a negative number, which means that SendAndReceive should do only a write, no read */ TCP_SetTimeout(moveSocket_, -0.1); pollSocket_ = pC_->pollSocket_; + + /* Set an EPICS exit handler that will shut down polling before asyn kills the IP sockets */ + epicsAtExit(shutdownCallback, pC_); setIntegerParam(pC_->motorStatusGainSupport_, 1); setIntegerParam(pC_->motorStatusHasEncoder_, 1);