diff --git a/Source/WPEFramework/PluginServer.cpp b/Source/WPEFramework/PluginServer.cpp index 90bd40ab47..856840a4b5 100644 --- a/Source/WPEFramework/PluginServer.cpp +++ b/Source/WPEFramework/PluginServer.cpp @@ -337,8 +337,8 @@ namespace PluginHost { Unlock(); result = Core::ERROR_ILLEGAL_STATE; } else if (currentState == IShell::state::HIBERNATED) { - Unlock(); result = Wakeup(3000); + Unlock(); } else if ((currentState == IShell::state::DEACTIVATED) || (currentState == IShell::state::PRECONDITION)) { // Load the interfaces, If we did not load them yet... @@ -524,9 +524,7 @@ namespace PluginHost { if(currentState == IShell::state::HIBERNATED) { - Unlock(); uint32_t wakeupResult = Wakeup(3000); - Lock(); if(wakeupResult != Core::ERROR_NONE) { //Force Activated state @@ -739,7 +737,13 @@ namespace PluginHost { result = Core::ERROR_NONE; #endif if (result == Core::ERROR_NONE) { - SYSLOG(Logging::Startup, (_T("Hibernated plugin [%s]:[%s]"), ClassName().c_str(), Callsign().c_str())); + if (State() == IShell::state::HIBERNATED) { + SYSLOG(Logging::Startup, ("Hibernated plugin [%s]:[%s]", ClassName().c_str(), Callsign().c_str())); + } else { + // wakeup occured right after hibernation finished + SYSLOG(Logging::Startup, ("Hibernation aborted of plugin [%s]:[%s]", ClassName().c_str(), Callsign().c_str())); + result = Core::ERROR_ABORTED; + } } else if (State() == IShell::state::HIBERNATED) { State(IShell::ACTIVATED); @@ -756,8 +760,6 @@ namespace PluginHost { uint32_t Server::Service::Wakeup(const uint32_t timeout VARIABLE_IS_NOT_USED) { Core::hresult result = Core::ERROR_NONE; - Lock(); - IShell::state currentState(State()); if (currentState != IShell::state::HIBERNATED) { @@ -791,7 +793,6 @@ namespace PluginHost { local->Release(); } } - Unlock(); return (result); } @@ -856,12 +857,13 @@ namespace PluginHost { Core::ProcessInfo::Iterator children(parentPID); if (children.Count() > 0) { - - while (children.Next()) { + // make sure to wakeup PIDs in opposite order to hibernation + // to quickly go over not hibernated PIDs and abort currently processed + children.Reset(false); + while (children.Previous()) { // Wakeup children of this process // There is no recovery path while doing Wakeup, don't care about errors WakeupChildren(children.Current().Id(), timeout); - TRACE(Activity, (_T("Wakeup of plugin [%s] child process [%u]"), Callsign().c_str(), children.Current().Id())); result = WakeupProcess(timeout, children.Current().Id(), _administrator.Configuration().HibernateLocator().c_str(), _T(""), &_hibernateStorage); } diff --git a/Source/core/ProcessInfo.h b/Source/core/ProcessInfo.h index 4581bdd72c..e1d0d16e5d 100644 --- a/Source/core/ProcessInfo.h +++ b/Source/core/ProcessInfo.h @@ -136,10 +136,15 @@ namespace Core { { return ((_index != 0) && (_index <= _pids.size())); } - inline void Reset() + inline void Reset(bool start = true) { - _index = 0; - _current = _pids.begin(); + if (start) { + _index = 0; + _current = _pids.begin(); + } else { + _index = _pids.size() + 1; + _current = _pids.end(); + } } bool Next() { @@ -152,6 +157,17 @@ namespace Core { } return (_index <= _pids.size()); } + bool Previous() + { + if (_index > 0) { + _index--; + + if (_index > 1) { + _current--; + } + } + return (_index > 0); + } inline ProcessInfo Current() const { ASSERT(IsValid() == true); diff --git a/Tests/unit/core/test_processinfo.cpp b/Tests/unit/core/test_processinfo.cpp index 588e826f89..c90ef391ec 100644 --- a/Tests/unit/core/test_processinfo.cpp +++ b/Tests/unit/core/test_processinfo.cpp @@ -41,9 +41,20 @@ TEST(Core_ProcessInfo, simpleSet) Core::ProcessInfo::Iterator childIterator = processInfo.Children(); + childIterator.Reset(false); + std::list pids; + std::cout << "Children (" << childIterator.Count() << ") in revers order" << std::endl; + while (childIterator.Previous()) { + Core::ProcessInfo childProcessInfo = childIterator.Current(); + std::cout << "\tName : " << childProcessInfo.Name() << " (" << childProcessInfo.Id() << "): " << childProcessInfo.Resident() << std::endl; + pids.push_front(childProcessInfo.Id()); + } + std::cout << "Children (" << childIterator.Count() << ") " << std::endl; while (childIterator.Next()) { Core::ProcessInfo childProcessInfo = childIterator.Current(); std::cout << "\tName : " << childProcessInfo.Name() << " (" << childProcessInfo.Id() << "): " << childProcessInfo.Resident() << std::endl; + EXPECT_EQ(childProcessInfo.Id(),pids.front()); + pids.pop_front(); } }