PulseAudio: Make FlushLoop more robust

When PA_CONTEXT_READY is called multiple times, PulseAudio::FlusLoop() would get stuck to to integer underflow.
Now there are multiple things preventing that.

Possible fix for https://github.com/scorpion-26/gBar/issues/7
This commit is contained in:
scorpion-26 2023-02-21 21:19:22 +01:00
parent 60b9355e88
commit 0e4b877654

View file

@ -11,14 +11,15 @@ namespace PulseAudio
static pa_mainloop* mainLoop;
static pa_context* context;
static uint32_t pending = 0;
static int32_t pending = 0;
inline void FlushLoop()
{
while (pending)
while (pending > 0)
{
pa_mainloop_iterate(mainLoop, 0, nullptr);
}
pending = 0;
}
inline void Init()
@ -41,7 +42,11 @@ namespace PulseAudio
case PA_CONTEXT_CONNECTING:
// Don't care
break;
case PA_CONTEXT_READY: pending--; break;
case PA_CONTEXT_READY:
// Prevent pending from going negative when PA_CONTEXT_READY is called multiple times
if (pending > 0)
pending--;
break;
}
};