summaryrefslogtreecommitdiff
path: root/chromium/ipc/mojo_event.h
blob: 079de284fc90f29e62b15abd5ca77b9b38bb0e3a (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
// Copyright 2016 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 IPC_MOJO_EVENT_H_
#define IPC_MOJO_EVENT_H_

#include "base/macros.h"
#include "base/synchronization/lock.h"
#include "mojo/public/cpp/system/message_pipe.h"

namespace IPC {

// A MojoEvent is a simple wrapper around a Mojo message pipe which supports
// common WaitableEvent-like methods of Signal() and Reset(). This class exists
// to support the transition from legacy IPC to Mojo IPC and is not intended for
// general use outside of src/ipc. Unlike base::WaitableEvent, all MojoEvents
// must be manually reset.
class MojoEvent {
 public:
  // Constructs a new MojoEvent that is initially not signaled.
  MojoEvent();

  ~MojoEvent();

  // Gets a Handle that can be waited on for this MojoEvent. When the Event is
  // signaled, this handle will have |MOJO_HANDLE_SIGNAL_READABLE| satisfied.
  const mojo::Handle& GetHandle() const { return wait_handle_.get(); }

  void Signal();
  void Reset();

 private:
  mojo::ScopedMessagePipeHandle signal_handle_;
  mojo::ScopedMessagePipeHandle wait_handle_;

  base::Lock lock_;
  bool is_signaled_ = false;

  DISALLOW_COPY_AND_ASSIGN(MojoEvent);
};

}  // namespace IPC

#endif  // IPC_MOJO_EVENT_H_