This is a fix for the CEventGroup deadlock.
authorJim Carroll <thecarrolls@jiminger.com>
Sun, 3 Jul 2011 15:25:11 +0000 (11:25 -0400)
committerJim Carroll <thecarrolls@jiminger.com>
Sun, 3 Jul 2011 15:56:47 +0000 (11:56 -0400)
commit1e1ff6503eac46d330e2263bcff2dadf9df4cd2a
tree46df7c7cb84b2645126980e7da7efc541fdc2fea
parent91efb0af6f80d82b104a810a1ccdc0ae6702d022
This is a fix for the CEventGroup deadlock.

There are several ways to do this. The easiest would have been simply to change the scope of the lock in the wait method on the CEventGroup so that it didn't include the reset (WaitMSec) calls on the child events. This would have made it the same as the older code (WaitForMultipleObjects here: https://github.com/xbmc/xbmc/commit/bb8858364ce3fcc64b87cdf1e08136fd5f8cb3dd#diff-92 ) but there is the potential for a race condition.

In order to avoid the race condition I prefered to make it so that whenever the group lock and child event lock are both required, they are always obtained in the same order. This requited doing the following:

1) Adding a lock for gating access to the CEventGroup's list of child CEvents
2) Making sure that the Set call on the CEvent and the CEventGroup::wait call both obtain the group's lock, followed by the child lock. The CEventGroup::wait already did this so code was added so that the CEvent::Set method could grab all of it's parent locks before grabbing it's own.

@elupus, please let me know if this makes sense to you. I tested it on the slideshow but I suspect the original deadlock was a rare occurance. I could go back and simply change the lock scope.
xbmc/threads/Event.cpp
xbmc/threads/Event.h