Skip to content

Commit

Permalink
Introduced onAliveChanged to CThreadBase
Browse files Browse the repository at this point in the history
This method can be used by children of CThreadBase to perform any child
specific actions when the alive state of this thread changes (e.g.,
release a mutex or semaphore).

Change-Id: I980b20517a8a58874a7717aa989308ab467df59f
  • Loading branch information
azoitl committed Mar 10, 2024
1 parent 4e7c9db commit 6c8a7db
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/arch/threadbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ namespace forte {
/*! \brief set the alive flag for this flag
*/
void setAlive(bool paVal) {
bool oldAlive = mAlive;
mAlive = paVal;
if(oldAlive != mAlive){
onAliveChanged(mAlive);
}
}

/*! \brief Helper method to run the thread.
Expand Down Expand Up @@ -129,6 +133,15 @@ namespace forte {
*/
virtual TThreadHandleType createThread(long paStackSize) = 0;


/*! \brief Call back allowing children to perform child specific actions on alive state changes
*
* @param paNewValue the new value of the alive flag
*/
virtual void onAliveChanged(bool paNewValue) {
(void)paNewValue; // inhibit compiler warning
}

//! Semaphore for implementing a generic join functionality. For a stable functionality this mutex must be locked during thread creation.
CSemaphore mJoinSem;

Expand Down
7 changes: 6 additions & 1 deletion src/core/ecet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ void CEventChainExecutionThread::run(){
}
}

void CEventChainExecutionThread::onAliveChanged(bool paNewValue) {
if(!paNewValue){
resumeSelfSuspend();
}
}

void CEventChainExecutionThread::mainRun(){
if(externalEventOccured()){
transferExternalEvents();
Expand Down Expand Up @@ -93,7 +99,6 @@ void CEventChainExecutionThread::changeExecutionState(EMGMCommandType paCommand)
[[fallthrough]];
case EMGMCommandType::Stop:
setAlive(false); //end thread in both cases
resumeSelfSuspend();
break;
default:
break;
Expand Down
2 changes: 2 additions & 0 deletions src/core/ecet.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class CEventChainExecutionThread : public CThread{
*/
void run() override;

void onAliveChanged(bool paNewValue) override;

/*! \brief Clear the event chain.
*/
void clear();
Expand Down

0 comments on commit 6c8a7db

Please sign in to comment.