Skip to content

Commit

Permalink
Merge pull request #180 from project8/feature/catchThreads
Browse files Browse the repository at this point in the history
Updated thread management in LMCKassSignalGenerator to match LMCArray…
  • Loading branch information
pslocum authored Feb 8, 2021
2 parents 5d37c09 + c7d8dba commit 216b263
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
7 changes: 6 additions & 1 deletion Source/Generators/LMCArraySignalGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace locust
fTextFileWriting( 0 ),
fphiLO(0.),
fNPreEventSamples( 150000 ),
fThreadCheckTime(10000),
EFieldBuffer( 1 ),
EPhaseBuffer( 1 ),
EAmplitudeBuffer( 1 ),
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions Source/Generators/LMCArraySignalGenerator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ namespace locust
std::vector< Channel<Receiver*> > 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;
Expand Down
28 changes: 25 additions & 3 deletions Source/Generators/LMCKassSignalGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace locust
fPhiLO_t(0.),
fNPreEventSamples( 15000 ),
fEventStartTime(-99.),
fThreadCheckTime(1000),
fEventToFile( false ),
fInterface( new KassLocustInterface() )

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions Source/Generators/LMCKassSignalGenerator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 216b263

Please sign in to comment.