MediaEventLooper: Add more safeness on exit

* The WaitForMessage is moved at the end of the loop, and
the check for quitting the loop is moved as it's condition,
this makes us to be sure that once a Quit() request is performed
we will not handle events anymore.
* Other minor style and initialization fixes.
This commit is contained in:
Dario Casalinuovo
2016-02-07 23:16:24 +01:00
parent 730d0700f5
commit 801b3e3bf4
+6 -10
View File
@@ -213,7 +213,7 @@ BMediaEventLooper::ControlLoop()
{ {
CALLED(); CALLED();
status_t err; status_t err = B_OK;
bigtime_t waitUntil = B_INFINITE_TIMEOUT; bigtime_t waitUntil = B_INFINITE_TIMEOUT;
bool hasRealtime = false; bool hasRealtime = false;
bool hasEvent = false; bool hasEvent = false;
@@ -224,11 +224,7 @@ BMediaEventLooper::ControlLoop()
// we need to handle the next event // we need to handle the next event
fSchedulingLatency = estimate_max_scheduling_latency(fControlThread); fSchedulingLatency = estimate_max_scheduling_latency(fControlThread);
while (true) { while (RunState() != B_QUITTING) {
if (RunState() == B_QUITTING)
return;
err = WaitForMessage(waitUntil);
if (err == B_TIMED_OUT if (err == B_TIMED_OUT
|| err == B_WOULD_BLOCK) { || err == B_WOULD_BLOCK) {
// NOTE: The reference for doing the lateness calculus this way can // NOTE: The reference for doing the lateness calculus this way can
@@ -255,7 +251,8 @@ BMediaEventLooper::ControlLoop()
if (waitUntil > 0) { if (waitUntil > 0) {
lateness = waitUntil - TimeSource()->RealTime(); lateness = waitUntil - TimeSource()->RealTime();
if (lateness > 0) { if (lateness > 0) {
bigtime_t enqueueLatency = event.enqueue_time - waitUntil; bigtime_t enqueueLatency
= event.enqueue_time - waitUntil;
if (enqueueLatency > 0) if (enqueueLatency > 0)
lateness += enqueueLatency; lateness += enqueueLatency;
} }
@@ -285,10 +282,8 @@ BMediaEventLooper::ControlLoop()
waitUntil = 0; waitUntil = 0;
hasBooted = true; hasBooted = true;
} }
} else if (!hasRealtime) { } else if (!hasRealtime)
waitUntil = B_INFINITE_TIMEOUT; waitUntil = B_INFINITE_TIMEOUT;
continue;
}
if (hasRealtime) { if (hasRealtime) {
bigtime_t realtimeWait = fRealTimeQueue.FirstEventTime() bigtime_t realtimeWait = fRealTimeQueue.FirstEventTime()
@@ -300,6 +295,7 @@ BMediaEventLooper::ControlLoop()
} else } else
hasRealtime = false; hasRealtime = false;
} }
err = WaitForMessage(waitUntil);
} }
} }