summaryrefslogtreecommitdiffstats
path: root/base/shared_event.h
blob: ee9e12d3309c48e65eff8664eb3ca47b4ebf49a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BASE_SHARED_EVENT__
#define BASE_SHARED_EVENT__

#include "base/process_util.h"

class TimeDelta;

typedef HANDLE SharedEventHandle;

class SharedEvent {
 public:
  // Create a new SharedEvent.
  SharedEvent() : event_handle_(NULL) { }

  // Create a SharedEvent from an existing SharedEventHandle.  The new
  // SharedEvent now owns the SharedEventHandle and will close it.
  SharedEvent(SharedEventHandle event_handle) : event_handle_(event_handle) { }
  ~SharedEvent();

  // Create the SharedEvent.
  bool Create(bool manual_reset, bool initial_state);

  // Close the SharedEvent.
  void Close();

  // If |signaled| is true, set the signaled state, otherwise, set to nonsignaled.
  // Returns false if we can't set the signaled state.
  bool SetSignaledState(bool signaled);

  // Returns true if the SharedEvent is signaled.
  bool IsSignaled();

  // Blocks until the event is signaled with a maximum wait time of |timeout|.
  // Returns true if the object is signaled within the timeout.
  bool WaitUntilSignaled(const TimeDelta& timeout);

  // Blocks until the event is signaled.  Returns true if the object is
  // signaled, otherwise an error occurred.
  bool WaitForeverUntilSignaled();

  // Get access to the underlying OS handle for this event.
  SharedEventHandle handle() { return event_handle_; }

  // Share this SharedEvent with |process|.  |new_handle| is an output
  // parameter to receive the handle for use in |process|.  Returns false if we
  // are unable to share the SharedEvent.
  bool ShareToProcess(ProcessHandle process, SharedEventHandle *new_handle);

  // The same as ShareToProcess followed by closing the event.
  bool GiveToProcess(ProcessHandle process, SharedEventHandle *new_handle);

 private:
  SharedEventHandle event_handle_;

  DISALLOW_EVIL_CONSTRUCTORS(SharedEvent);
};

#endif  // BASE_SHARED_EVENT__