How can you tell whether a WM_POWERBROADCAST message has interrupted a call stack? As opposed to happening in isolation with just the message handler call stack?
Here's the background: What I see is that during hibernate / resume I get WM_POWERBROADCAST messages. These can seemingly interrupt a (blocked/waiting) callstack for e.g. a WM_USER message, or interrupt each other.
This is causing a problem because in the WM_POWERBROADCAST handler I need to call into a third party library to correctly handle the message, but if the application was already waiting for an API call to return from that library it leads to a deadlock. Similar problems were happening when the WM_POWERBROADCAST interrupts itself, but that case is easier to identify using a state variable.
e.g. the call stack can look like some variation of this:
OnSomeUserMessageHandler ()
...
CallIntoThirdPartyAPI ()
OnPowerBroadcast ()
...
OnPowerBroadcast ()
DifferentCallIntoThirdPartyAPI ()
*deadlock*
I could manage a state variable in every single message handler, but I'm hoping there is a simpler and more robust way to identify this condition.
This is a MFC app. Basically I want to be able to do:
MyWindow::OnPowerBroadcast (UINT nPowerEvent, UINT nEventData
{
if (InterruptedSomebodysCallStack ())
{
// do something
}
else // basic isolated OnPowerBroadcast handler
{
// do something else
}
}
Or have the WM_POWERBROADCAST messages wait their turn like the WM_USER messages seemingly do.