Skip to content

Commit 8288696

Browse files
committed
Wait added to clear child list
1 parent e8e6d2a commit 8288696

2 files changed

Lines changed: 25 additions & 12 deletions

File tree

Launcher.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,7 @@ void Launcher::Update(const ProcessObserver::Info& info)
8989
switch (info.Event()) {
9090
case ProcessObserver::Info::EVENT_FORK:
9191
TRACE(Trace::Information, (_T("FORK: parent tid=%d pid=%d -> child tid=%d pid=%d\n"), info.Id(), info.Group(), info.ChildId(), info.ChildGroup()));
92-
if (_activity->ShutdownInProgress() == false) {
93-
_activity->AddPid(info.ChildId());
94-
} else {
95-
_activity->Kill(info.ChildId());
96-
}
92+
_activity->AddPid(info.ChildId());
9793
break;
9894
case ProcessObserver::Info::EVENT_EXEC:
9995
TRACE(Trace::Information, (_T("EXEC: tid=%d pid=%d\n"), info.Id(), info.Group()));

Launcher.h

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ class Launcher : public PluginHost::IPlugin {
557557
, _interval(interval)
558558
, _closeTime(config->CloseTime.Value())
559559
, _shutdownPhase(0)
560+
, _waitEvent(true, false)
560561
{
561562
auto iter = config->Parameters.Elements();
562563

@@ -590,8 +591,12 @@ class Launcher : public PluginHost::IPlugin {
590591
return _pid;
591592
}
592593
bool ShutdownInProgress() {
593-
return _shutdownPhase;
594-
}
594+
bool status = false;
595+
_adminLock.Lock();
596+
status = _shutdownPhase;
597+
_adminLock.Unlock();
598+
return status;
599+
}
595600
void Kill(uint32_t pid) {
596601
::kill(pid, SIGKILL);
597602
}
@@ -603,8 +608,13 @@ class Launcher : public PluginHost::IPlugin {
603608
}
604609
void AddPid(uint32_t pid) {
605610
_adminLock.Lock();
606-
ASSERT(std::find(_processList.begin(), _processList.end(), pid) == _processList.end());
607-
_processList.push_back(pid);
611+
if (!_shutdownPhase) {
612+
ASSERT(std::find(_processList.begin(), _processList.end(), pid) == _processList.end());
613+
_processList.push_back(pid);
614+
}
615+
else {
616+
Kill(pid);
617+
}
608618
_adminLock.Unlock();
609619
}
610620
void RemovePid(uint32_t pid) {
@@ -613,15 +623,17 @@ class Launcher : public PluginHost::IPlugin {
613623
if (position != _processList.end()) {
614624
_processList.erase(position);
615625
}
626+
if (_processList.empty() == true) {
627+
_waitEvent.SetEvent();
628+
}
616629
_adminLock.Unlock();
617630
}
618631
void StopChilds() {
619632
_adminLock.Lock();
620633
ASSERT(!_processList.empty())
621634
for (int i = 1; i < _processList.size(); i++) {
622-
Kill(_processList[i];);
635+
Kill(_processList[i]);
623636
}
624-
_processList.clear(); //Clear to ensure it is removed before doing the force shutdown
625637
_adminLock.Unlock();
626638
}
627639
void Schedule (const Core::Time& time) {
@@ -638,7 +650,7 @@ class Launcher : public PluginHost::IPlugin {
638650
_adminLock.Unlock();
639651

640652
(PluginHost::WorkerPool::Instance().Revoke(Core::ProxyType<Core::IDispatch>(*this)));
641-
653+
_waitEvent.ResetEvent();
642654
if (_process.IsActive() == true) {
643655

644656
// First try a gentle touch....
@@ -651,6 +663,10 @@ class Launcher : public PluginHost::IPlugin {
651663
_process.WaitProcessCompleted(1000);
652664
}
653665
StopChilds(); //Ensure all childs are exited before quiting
666+
if (_waitEvent.Lock(1000) != Core::ERROR_NONE) {
667+
TRACE_L1("Child list are not yet cleared\n");
668+
_processList.clear();
669+
}
654670
}
655671
}
656672

@@ -693,6 +709,7 @@ class Launcher : public PluginHost::IPlugin {
693709
uint8_t _closeTime;
694710
uint8_t _shutdownPhase;
695711
ProcessList _processList;
712+
Core::Event _waitEvent;
696713
};
697714

698715
public:

0 commit comments

Comments
 (0)