• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2016 Marshall A. Greenblatt. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 //    * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 //    * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 //    * Neither the name of Google Inc. nor the name Chromium Embedded
14 // Framework nor the names of its contributors may be used to endorse
15 // or promote products derived from this software without specific prior
16 // written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // ---------------------------------------------------------------------------
31 //
32 // The contents of this file must follow a specific format in order to
33 // support the CEF translator tool. See the translator.README.txt file in the
34 // tools directory for more information.
35 //
36 
37 #ifndef CEF_INCLUDE_CEF_WAITABLE_EVENT_H_
38 #define CEF_INCLUDE_CEF_WAITABLE_EVENT_H_
39 #pragma once
40 
41 #include "include/cef_base.h"
42 
43 ///
44 // WaitableEvent is a thread synchronization tool that allows one thread to wait
45 // for another thread to finish some work. This is equivalent to using a
46 // Lock+ConditionVariable to protect a simple boolean value. However, using
47 // WaitableEvent in conjunction with a Lock to wait for a more complex state
48 // change (e.g., for an item to be added to a queue) is not recommended. In that
49 // case consider using a ConditionVariable instead of a WaitableEvent. It is
50 // safe to create and/or signal a WaitableEvent from any thread. Blocking on a
51 // WaitableEvent by calling the *Wait() methods is not allowed on the browser
52 // process UI or IO threads.
53 ///
54 /*--cef(source=library)--*/
55 class CefWaitableEvent : public CefBaseRefCounted {
56  public:
57   ///
58   // Create a new waitable event. If |automatic_reset| is true then the event
59   // state is automatically reset to un-signaled after a single waiting thread
60   // has been released; otherwise, the state remains signaled until Reset() is
61   // called manually. If |initially_signaled| is true then the event will start
62   // in the signaled state.
63   ///
64   /*--cef()--*/
65   static CefRefPtr<CefWaitableEvent> CreateWaitableEvent(
66       bool automatic_reset,
67       bool initially_signaled);
68 
69   ///
70   // Put the event in the un-signaled state.
71   ///
72   /*--cef()--*/
73   virtual void Reset() = 0;
74 
75   ///
76   // Put the event in the signaled state. This causes any thread blocked on Wait
77   // to be woken up.
78   ///
79   /*--cef()--*/
80   virtual void Signal() = 0;
81 
82   ///
83   // Returns true if the event is in the signaled state, else false. If the
84   // event was created with |automatic_reset| set to true then calling this
85   // method will also cause a reset.
86   ///
87   /*--cef()--*/
88   virtual bool IsSignaled() = 0;
89 
90   ///
91   // Wait indefinitely for the event to be signaled. This method will not return
92   // until after the call to Signal() has completed. This method cannot be
93   // called on the browser process UI or IO threads.
94   ///
95   /*--cef()--*/
96   virtual void Wait() = 0;
97 
98   ///
99   // Wait up to |max_ms| milliseconds for the event to be signaled. Returns true
100   // if the event was signaled. A return value of false does not necessarily
101   // mean that |max_ms| was exceeded. This method will not return until after
102   // the call to Signal() has completed. This method cannot be called on the
103   // browser process UI or IO threads.
104   ///
105   /*--cef()--*/
106   virtual bool TimedWait(int64 max_ms) = 0;
107 };
108 
109 #endif  // CEF_INCLUDE_CEF_WAITABLE_EVENT_H_
110