blob: ee9e12d3309c48e65eff8664eb3ca47b4ebf49a0 [file] [log] [blame]
license.botf003cfe2008-08-24 09:55:55 +09001// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit3f4a7322008-07-27 06:49:38 +09004
5#ifndef BASE_SHARED_EVENT__
6#define BASE_SHARED_EVENT__
7
8#include "base/process_util.h"
9
10class TimeDelta;
11
12typedef HANDLE SharedEventHandle;
13
14class SharedEvent {
15 public:
16 // Create a new SharedEvent.
17 SharedEvent() : event_handle_(NULL) { }
18
19 // Create a SharedEvent from an existing SharedEventHandle. The new
20 // SharedEvent now owns the SharedEventHandle and will close it.
21 SharedEvent(SharedEventHandle event_handle) : event_handle_(event_handle) { }
22 ~SharedEvent();
23
24 // Create the SharedEvent.
25 bool Create(bool manual_reset, bool initial_state);
26
27 // Close the SharedEvent.
28 void Close();
29
30 // If |signaled| is true, set the signaled state, otherwise, set to nonsignaled.
31 // Returns false if we can't set the signaled state.
32 bool SetSignaledState(bool signaled);
33
34 // Returns true if the SharedEvent is signaled.
35 bool IsSignaled();
36
37 // Blocks until the event is signaled with a maximum wait time of |timeout|.
38 // Returns true if the object is signaled within the timeout.
39 bool WaitUntilSignaled(const TimeDelta& timeout);
40
41 // Blocks until the event is signaled. Returns true if the object is
42 // signaled, otherwise an error occurred.
43 bool WaitForeverUntilSignaled();
44
45 // Get access to the underlying OS handle for this event.
46 SharedEventHandle handle() { return event_handle_; }
47
48 // Share this SharedEvent with |process|. |new_handle| is an output
49 // parameter to receive the handle for use in |process|. Returns false if we
50 // are unable to share the SharedEvent.
51 bool ShareToProcess(ProcessHandle process, SharedEventHandle *new_handle);
52
53 // The same as ShareToProcess followed by closing the event.
54 bool GiveToProcess(ProcessHandle process, SharedEventHandle *new_handle);
55
56 private:
57 SharedEventHandle event_handle_;
58
59 DISALLOW_EVIL_CONSTRUCTORS(SharedEvent);
60};
61
62#endif // BASE_SHARED_EVENT__
license.botf003cfe2008-08-24 09:55:55 +090063