summaryrefslogtreecommitdiff
path: root/chromium/ipc/mojo_event.cc
blob: 5d802b8bff9721224756d53f670bdbab26af6dcb (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
// 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.

#include "ipc/mojo_event.h"

namespace IPC {

MojoEvent::MojoEvent() {
  mojo::MessagePipe pipe;
  signal_handle_ = std::move(pipe.handle0);
  wait_handle_ = std::move(pipe.handle1);
}

MojoEvent::~MojoEvent() {}

void MojoEvent::Signal() {
  base::AutoLock lock(lock_);
  if (is_signaled_)
    return;
  is_signaled_ = true;
  MojoResult rv = mojo::WriteMessageRaw(
      signal_handle_.get(), nullptr, 0, nullptr, 0,
      MOJO_WRITE_MESSAGE_FLAG_NONE);
  CHECK_EQ(rv, MOJO_RESULT_OK);
}

void MojoEvent::Reset() {
  base::AutoLock lock(lock_);
  if (!is_signaled_)
    return;
  is_signaled_ = false;
  MojoResult rv = mojo::ReadMessageRaw(
      wait_handle_.get(), nullptr, nullptr, nullptr, nullptr,
      MOJO_READ_MESSAGE_FLAG_NONE);
  CHECK_EQ(rv, MOJO_RESULT_OK);
}

}  // namespace IPC