• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that can
3 // be found in the LICENSE file.
4 
5 #include "libcef/common/waitable_event_impl.h"
6 
7 #include "include/cef_task.h"
8 
9 #include "base/notreached.h"
10 #include "base/time/time.h"
11 
12 namespace {
13 
AllowWait()14 bool AllowWait() {
15   if (CefCurrentlyOn(TID_UI) || CefCurrentlyOn(TID_IO)) {
16     NOTREACHED() << "waiting is not allowed on the current thread";
17     return false;
18   }
19   return true;
20 }
21 
22 }  // namespace
23 
24 // static
CreateWaitableEvent(bool automatic_reset,bool initially_signaled)25 CefRefPtr<CefWaitableEvent> CefWaitableEvent::CreateWaitableEvent(
26     bool automatic_reset,
27     bool initially_signaled) {
28   return new CefWaitableEventImpl(automatic_reset, initially_signaled);
29 }
30 
CefWaitableEventImpl(bool automatic_reset,bool initially_signaled)31 CefWaitableEventImpl::CefWaitableEventImpl(bool automatic_reset,
32                                            bool initially_signaled)
33     : event_(automatic_reset ? base::WaitableEvent::ResetPolicy::AUTOMATIC
34                              : base::WaitableEvent::ResetPolicy::MANUAL,
35              initially_signaled
36                  ? base::WaitableEvent::InitialState::SIGNALED
37                  : base::WaitableEvent::InitialState::NOT_SIGNALED) {}
38 
Reset()39 void CefWaitableEventImpl::Reset() {
40   event_.Reset();
41 }
42 
Signal()43 void CefWaitableEventImpl::Signal() {
44   event_.Signal();
45 }
46 
IsSignaled()47 bool CefWaitableEventImpl::IsSignaled() {
48   return event_.IsSignaled();
49 }
50 
Wait()51 void CefWaitableEventImpl::Wait() {
52   if (!AllowWait())
53     return;
54   event_.Wait();
55 }
56 
TimedWait(int64 max_ms)57 bool CefWaitableEventImpl::TimedWait(int64 max_ms) {
58   if (!AllowWait())
59     return false;
60   return event_.TimedWait(base::TimeDelta::FromMilliseconds(max_ms));
61 }
62