xbmc/xbmc — pull request #2244 by ulion (2013-02-15 16:16:27+00:00)
Title: Fix race conditions after starting flag reset, make sure play state callbacks are called and only called once.

this PR trace the starting playing item's play state callback state change, with lock protect.
with this, kill the race condition in original code in PlayFile after starting flag reset.
there is chance OnPlaybackStarted/OnPlaybackEnded be called twice (once by xbmc main thread in the place, once by player thread called just after the starting flag set to false). or other race condition between IsPlaying() check and OnPlaybackStarted/OnPlaybackEnded/OnPlaybackStopped callbacks.
since we had to delay the callback process during starting state, we need to record which callbacks were called during starting state, so I add code for tracing that, and also need to not bother by the previous playing item's stopped/ended callback.
finally after starting state finished, we do the callback happened during starting state, that's all this commit does.
I did this because in https://github.com/xbmc/xbmc/pull/2228 @elupus said there is race condition if OpenFile return true, I checked, there indeed is race condition, but not caused by PR 2228, it existed for years, PR 2228 did work for fixing the crash and not related to the race condition mentioned. So I finally figure a way in this PR to kill the race condition, how does this like?