mmdevapi: Prevent race condition upon Start.

Joerg-Cyril.Hoehle at Joerg-Cyril.Hoehle at
Mon Dec 17 09:23:12 CST 2012


What happened every so often, even on a single-core machine(!), is
that CreateTimerQueue(dueTime=0=immediate) would see the timer thread
created and the callback invoked before the function returns.  Since
This->started was not set yet, our callback would return immediately,
in effect causing sound to start only one 10ms period later.
That's obviously was not intended by the author.
So let's set This->started before CTQ.

Furthermore, my belief is that the native audio engine ticks
independently on the clients.  That implies that SetEventHandle events
are fired non-deterministically after IAC_Start within the next
0-10ms.  So let's choose 2 or 5ms and make it deterministic.
Especially I want to avoid dueTime=0=immediate.

If you check winecoreaudio, you'll see a bug: CTQ is not called last
within IAC_Start.  If the subsequent AudioQueueStart fails,
This->playing is not reset to a StateXYZ that'll let IAC_Stop delete
the timer queue.  Events will be fired forever...

If nobody jumps in, perhaps I'll feel the mood and write a patch
that'll simultaneously continue sending events after IAC_Stop, as the
tests show it should.

	Jörg Höhle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-mmdevapi-Prevent-race-condition-upon-Start.patch
Type: application/octet-stream
Size: 3122 bytes
Desc: 0001-mmdevapi-Prevent-race-condition-upon-Start.patch
URL: <>

More information about the wine-patches mailing list