16e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org/*
2a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgSource:
3a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orghttp://www1.cse.wustl.edu/~schmidt/ACE-copying.html
4a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.org
5a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgLicense:
6a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgCopyright and Licensing Information for ACE(TM), TAO(TM), CIAO(TM), DAnCE(TM),
7a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.organd CoSMIC(TM)
8a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.org
9a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgACE(TM), TAO(TM), CIAO(TM), DAnCE>(TM), and CoSMIC(TM) (henceforth referred to
10a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgas "DOC software") are copyrighted by Douglas C. Schmidt and his research
11a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orggroup at Washington University, University of California, Irvine, and
12a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgVanderbilt University, Copyright (c) 1993-2009, all rights reserved. Since DOC
13a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgsoftware is open-source, freely available software, you are free to use,
14a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgmodify, copy, and distribute--perpetually and irrevocably--the DOC software
15a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgsource code and object code produced from the source, as well as copy and
16a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgdistribute modified versions of this software. You must, however, include this
17a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgcopyright statement along with any code built using DOC software that you
18a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgrelease. No copyright statement needs to be provided if you just ship binary
19a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgexecutables of your software products.
20a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgYou can use DOC software in commercial and/or binary software releases and are
21a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgunder no obligation to redistribute any of your source code that is built
22a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgusing DOC software. Note, however, that you may not misappropriate the DOC
23a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgsoftware code, such as copyrighting it yourself or claiming authorship of the
24a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgDOC software code, in a way that will prevent DOC software from being
25a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgdistributed freely using an open-source development model. You needn't inform
26a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.organyone that you're using DOC software in your software, though we encourage
27a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgyou to let us know so we can promote your project in the DOC software success
28a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgstories.
29a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.org
30a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgThe ACE, TAO, CIAO, DAnCE, and CoSMIC web sites are maintained by the DOC
31a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgGroup at the Institute for Software Integrated Systems (ISIS) and the Center
32a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgfor Distributed Object Computing of Washington University, St. Louis for the
33a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgdevelopment of open-source software as part of the open-source software
34a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgcommunity. Submissions are provided by the submitter ``as is'' with no
35a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgwarranties whatsoever, including any warranty of merchantability,
36a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgnoninfringement of third party intellectual property, or fitness for any
37a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgparticular purpose. In no event shall the submitter be liable for any direct,
38a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgindirect, special, exemplary, punitive, or consequential damages, including
39a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgwithout limitation, lost profits, even if advised of the possibility of such
40a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgdamages. Likewise, DOC software is provided as is with no warranties of any
41a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgkind, including the warranties of design, merchantability, and fitness for a
42a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgparticular purpose, noninfringement, or arising from a course of dealing,
43a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgusage or trade practice. Washington University, UC Irvine, Vanderbilt
44a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgUniversity, their employees, and students shall have no liability with respect
45a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgto the infringement of copyrights, trade secrets or any patents by DOC
46a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgsoftware or any part thereof. Moreover, in no event will Washington
47a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgUniversity, UC Irvine, or Vanderbilt University, their employees, or students
48a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgbe liable for any lost revenue or profits or other special, indirect and
49a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgconsequential damages.
50a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.org
51a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgDOC software is provided with no support and without any obligation on the
52a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgpart of Washington University, UC Irvine, Vanderbilt University, their
53a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgemployees, or students to assist in its use, correction, modification, or
54a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgenhancement. A number of companies around the world provide commercial support
55a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgfor DOC software, however. DOC software is Y2K-compliant, as long as the
56a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgunderlying OS platform is Y2K-compliant. Likewise, DOC software is compliant
57a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgwith the new US daylight savings rule passed by Congress as "The Energy Policy
58a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgAct of 2005," which established new daylight savings times (DST) rules for the
59a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgUnited States that expand DST as of March 2007. Since DOC software obtains
60a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgtime/date and calendaring information from operating systems users will not be
61a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgaffected by the new DST rules as long as they upgrade their operating systems
62a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgaccordingly.
63a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.org
64a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgThe names ACE(TM), TAO(TM), CIAO(TM), DAnCE(TM), CoSMIC(TM), Washington
65a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgUniversity, UC Irvine, and Vanderbilt University, may not be used to endorse
66a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgor promote products or services derived from this source without express
67a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgwritten permission from Washington University, UC Irvine, or Vanderbilt
68a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgUniversity. This license grants no permission to call products or services
69a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgderived from this source ACE(TM), TAO(TM), CIAO(TM), DAnCE(TM), or CoSMIC(TM),
70a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgnor does it grant permission for the name Washington University, UC Irvine, or
71a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.orgVanderbilt University to appear in their names.
72a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.org*/
73a0975ed35e395b79d4c617e57c8c4ed6337087bfandrew@webrtc.org
746e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org/*
756e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org *  This source code contain modifications to the original source code
766e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org *  which can be found here:
776e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org *  http://www.cs.wustl.edu/~schmidt/win32-cv-1.html (section 3.2).
786e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org *  Modifications:
796e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org *  1) Dynamic detection of native support for condition variables.
806e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org *  2) Use of WebRTC defined types and classes. Renaming of some functions.
816e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org *  3) Introduction of a second event for wake all functionality. This prevents
826e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org *     a thread from spinning on the same condition variable, preventing other
836e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org *     threads from waking up.
846e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org */
856e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org
866e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org#include "webrtc/system_wrappers/source/condition_variable_event_win.h"
876e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org#include "webrtc/system_wrappers/source/critical_section_win.h"
886e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org
896e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.orgnamespace webrtc {
906e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org
916e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.orgConditionVariableEventWin::ConditionVariableEventWin() : eventID_(WAKEALL_0) {
926e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  memset(&num_waiters_[0], 0, sizeof(num_waiters_));
936e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org
946e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  InitializeCriticalSection(&num_waiters_crit_sect_);
956e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org
966e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  events_[WAKEALL_0] = CreateEvent(NULL,  // no security attributes
976e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org                                   TRUE,  // manual-reset, sticky event
986e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org                                   FALSE,  // initial state non-signaled
996e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org                                   NULL);  // no name for event
1006e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org
1016e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  events_[WAKEALL_1] = CreateEvent(NULL,  // no security attributes
1026e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org                                   TRUE,  // manual-reset, sticky event
1036e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org                                   FALSE,  // initial state non-signaled
1046e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org                                   NULL);  // no name for event
1056e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org
1066e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  events_[WAKE] = CreateEvent(NULL,  // no security attributes
1076e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org                              FALSE,  // auto-reset, sticky event
1086e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org                              FALSE,  // initial state non-signaled
1096e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org                              NULL);  // no name for event
1106e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org}
1116e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org
1126e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.orgConditionVariableEventWin::~ConditionVariableEventWin() {
1136e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  CloseHandle(events_[WAKE]);
1146e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  CloseHandle(events_[WAKEALL_1]);
1156e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  CloseHandle(events_[WAKEALL_0]);
1166e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org
1176e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  DeleteCriticalSection(&num_waiters_crit_sect_);
1186e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org}
1196e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org
1206e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.orgvoid ConditionVariableEventWin::SleepCS(CriticalSectionWrapper& crit_sect) {
1216e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  SleepCS(crit_sect, INFINITE);
1226e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org}
1236e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org
1246e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.orgbool ConditionVariableEventWin::SleepCS(CriticalSectionWrapper& crit_sect,
1256e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org                                        unsigned long max_time_in_ms) {
1266e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  EnterCriticalSection(&num_waiters_crit_sect_);
1276e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org
1286e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  // Get the eventID for the event that will be triggered by next
1296e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  // WakeAll() call and start waiting for it.
1306e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  const EventWakeUpType eventID =
1316e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org      (WAKEALL_0 == eventID_) ? WAKEALL_1 : WAKEALL_0;
1326e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org
1336e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  ++(num_waiters_[eventID]);
1346e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  LeaveCriticalSection(&num_waiters_crit_sect_);
1356e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org
1366e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  CriticalSectionWindows* cs =
1376e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org      static_cast<CriticalSectionWindows*>(&crit_sect);
1386e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  LeaveCriticalSection(&cs->crit);
1396e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  HANDLE events[2];
1406e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  events[0] = events_[WAKE];
1416e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  events[1] = events_[eventID];
1426e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  const DWORD result = WaitForMultipleObjects(2,  // Wait on 2 events.
1436e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org                                              events,
1446e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org                                              FALSE,  // Wait for either.
1456e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org                                              max_time_in_ms);
1466e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org
1476e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  const bool ret_val = (result != WAIT_TIMEOUT);
1486e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org
1496e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  EnterCriticalSection(&num_waiters_crit_sect_);
1506e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  --(num_waiters_[eventID]);
1516e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org
1526e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  // Last waiter should only be true for WakeAll(). WakeAll() correspond
1536e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  // to position 1 in events[] -> (result == WAIT_OBJECT_0 + 1)
1546e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  const bool last_waiter = (result == WAIT_OBJECT_0 + 1) &&
1556e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org      (num_waiters_[eventID] == 0);
1566e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  LeaveCriticalSection(&num_waiters_crit_sect_);
1576e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org
1586e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  if (last_waiter) {
1596e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org    // Reset/unset the WakeAll() event since all threads have been
1606e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org    // released.
1616e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org    ResetEvent(events_[eventID]);
1626e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  }
1636e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org
1646e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  EnterCriticalSection(&cs->crit);
1656e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  return ret_val;
1666e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org}
1676e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org
1686e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.orgvoid ConditionVariableEventWin::Wake() {
1696e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  EnterCriticalSection(&num_waiters_crit_sect_);
1706e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  const bool have_waiters = (num_waiters_[WAKEALL_0] > 0) ||
1716e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org      (num_waiters_[WAKEALL_1] > 0);
1726e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  LeaveCriticalSection(&num_waiters_crit_sect_);
1736e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org
1746e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  if (have_waiters) {
1756e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org    SetEvent(events_[WAKE]);
1766e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  }
1776e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org}
1786e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org
1796e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.orgvoid ConditionVariableEventWin::WakeAll() {
1806e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  EnterCriticalSection(&num_waiters_crit_sect_);
1816e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org
1826e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  // Update current WakeAll() event
1836e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  eventID_ = (WAKEALL_0 == eventID_) ? WAKEALL_1 : WAKEALL_0;
1846e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org
1856e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  // Trigger current event
1866e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  const EventWakeUpType eventID = eventID_;
1876e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  const bool have_waiters = num_waiters_[eventID] > 0;
1886e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  LeaveCriticalSection(&num_waiters_crit_sect_);
1896e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org
1906e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  if (have_waiters) {
1916e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org    SetEvent(events_[eventID]);
1926e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org  }
1936e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org}
1946e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org
1956e34ceb97c11f4d390742a8364e77a65b8a01200henrike@webrtc.org}  // namespace webrtc
196