From c7d8dbaa0bc91fa0764ab942d034ec781a65ec0d Mon Sep 17 00:00:00 2001 From: Penny Slocum Date: Mon, 8 Feb 2021 13:15:57 -0500 Subject: [PATCH] Updated thread management in LMCKassSignalGenerator to match LMCArraySigalGenerator, for symmetry. Parametrized time to check status of event start in both generators. --- Source/Generators/LMCArraySignalGenerator.cc | 7 ++++- Source/Generators/LMCArraySignalGenerator.hh | 1 + Source/Generators/LMCKassSignalGenerator.cc | 28 +++++++++++++++++--- Source/Generators/LMCKassSignalGenerator.hh | 1 + 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Source/Generators/LMCArraySignalGenerator.cc b/Source/Generators/LMCArraySignalGenerator.cc index 722f7465..96f96ff9 100644 --- a/Source/Generators/LMCArraySignalGenerator.cc +++ b/Source/Generators/LMCArraySignalGenerator.cc @@ -33,6 +33,7 @@ namespace locust fTextFileWriting( 0 ), fphiLO(0.), fNPreEventSamples( 150000 ), + fThreadCheckTime(10000), EFieldBuffer( 1 ), EPhaseBuffer( 1 ), EAmplitudeBuffer( 1 ), @@ -298,6 +299,10 @@ namespace locust { fNPreEventSamples = aParam["event-spacing-samples"]().as_int(); } + if( aParam.has( "thread-check-time" ) ) + { + fThreadCheckTime = aParam["thread-check-time"]().as_int(); + } if( aParam.has( "swap-frequency" ) ) { fSwapFrequency = aParam["swap-frequency"]().as_int(); @@ -642,7 +647,7 @@ namespace locust else // either Kass thread fell behind, or it has stopped generating events. { tLock.lock(); - std::this_thread::sleep_for(std::chrono::milliseconds(10000)); + std::this_thread::sleep_for(std::chrono::milliseconds(fThreadCheckTime)); if (!fInterface->fKassEventReady) // Kass event did start. Continue but skip this sample. { tLock.unlock(); diff --git a/Source/Generators/LMCArraySignalGenerator.hh b/Source/Generators/LMCArraySignalGenerator.hh index 7ea0163e..cf0b5747 100644 --- a/Source/Generators/LMCArraySignalGenerator.hh +++ b/Source/Generators/LMCArraySignalGenerator.hh @@ -82,6 +82,7 @@ namespace locust std::vector< Channel > allRxChannels; //Vector of channels with pointers to Rx elements. double fLO_Frequency; int fNPreEventSamples; // spacing between events. constant for now, could be randomized. + int fThreadCheckTime; // time (ms) to check for response from Kass thread. double fArrayRadius; int fNElementsPerStrip; int fNSubarrays; diff --git a/Source/Generators/LMCKassSignalGenerator.cc b/Source/Generators/LMCKassSignalGenerator.cc index ac3e7893..e4fa4b63 100644 --- a/Source/Generators/LMCKassSignalGenerator.cc +++ b/Source/Generators/LMCKassSignalGenerator.cc @@ -32,6 +32,7 @@ namespace locust fPhiLO_t(0.), fNPreEventSamples( 15000 ), fEventStartTime(-99.), + fThreadCheckTime(1000), fEventToFile( false ), fInterface( new KassLocustInterface() ) @@ -77,6 +78,11 @@ namespace locust fNPreEventSamples = aParam["event-spacing-samples"]().as_int(); } + if( aParam.has( "thread-check-time" ) ) + { + fThreadCheckTime = aParam["thread-check-time"]().as_int(); + } + if( aParam.has( "center-to-short" ) ) { fInterface->fCENTER_TO_SHORT = aParam["center-to-short"]().as_double(); @@ -323,13 +329,14 @@ namespace locust fInterface->fEventInProgress = true; LPROG( lmclog, "LMC about to WakeBeforeEvent()" ); WakeBeforeEvent(); // trigger Kass event. - std::this_thread::sleep_for(std::chrono::milliseconds(100)); } } - if ((fInterface->fEventInProgress)&&(!fInterface->fKassEventReady)) // fEventInProgress + if (fInterface->fEventInProgress) // fEventInProgress { - std::unique_lock< std::mutex >tLock( fInterface->fMutexDigitizer, std::defer_lock ); + std::unique_lock< std::mutex >tLock( fInterface->fMutexDigitizer, std::defer_lock ); + if (!fInterface->fKassEventReady) // Kass confirms event is underway. + { tLock.lock(); fInterface->fDigitizerCondition.wait( tLock ); if (fInterface->fEventInProgress) @@ -338,6 +345,21 @@ namespace locust PreEventCounter = 0; // reset } tLock.unlock(); + } + else // either Kass thread fell behind, or it has stopped generating events. + { + tLock.lock(); + std::this_thread::sleep_for(std::chrono::milliseconds(fThreadCheckTime)); + if (!fInterface->fKassEventReady) // Kass event did start. Continue but skip this sample. + { + tLock.unlock(); + } + else // no Kass event ever started, unlock and break out of signal loop entirely. + { + tLock.unlock(); + break; + } + } } } // for loop diff --git a/Source/Generators/LMCKassSignalGenerator.hh b/Source/Generators/LMCKassSignalGenerator.hh index 34be5658..07434628 100644 --- a/Source/Generators/LMCKassSignalGenerator.hh +++ b/Source/Generators/LMCKassSignalGenerator.hh @@ -70,6 +70,7 @@ namespace locust double fPhi_t2; // reflecting short voltage phase in radians. double fPhiLO_t; // voltage phase of LO in radians; int fNPreEventSamples; // spacing between events. constant for now, could be randomized. + int fThreadCheckTime; // time (ms) to check for response from Kass thread. mutable double fPreviousRetardedTime; mutable int fPreviousRetardedIndex; double fEventStartTime;