Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
lockers.h
Go to the documentation of this file.
1// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_BIN_LOCKERS_H_
6#define RUNTIME_BIN_LOCKERS_H_
7
8#include "bin/thread.h"
9#include "platform/assert.h"
10
11namespace dart {
12namespace bin {
13
15 public:
16 explicit MutexLocker(Mutex* mutex) : mutex_(mutex) {
17 ASSERT(mutex != nullptr);
18 mutex_->Lock();
19 }
20
21 virtual ~MutexLocker() { mutex_->Unlock(); }
22
23 private:
24 Mutex* const mutex_;
25
27};
28
30 public:
31 explicit MonitorLocker(Monitor* monitor) : monitor_(monitor) {
32 ASSERT(monitor != nullptr);
33 monitor_->Enter();
34 }
35
36 virtual ~MonitorLocker() { monitor_->Exit(); }
37
39 return monitor_->Wait(millis);
40 }
41
42 void Notify() { monitor_->Notify(); }
43
44 void NotifyAll() { monitor_->NotifyAll(); }
45
46 private:
47 Monitor* const monitor_;
48
50};
51
52} // namespace bin
53} // namespace dart
54
55#endif // RUNTIME_BIN_LOCKERS_H_
Monitor::WaitResult Wait(int64_t millis=Monitor::kNoTimeout)
Definition lockers.h:38
virtual ~MonitorLocker()
Definition lockers.h:36
MonitorLocker(Monitor *monitor)
Definition lockers.h:31
static constexpr int64_t kNoTimeout
Definition thread.h:79
WaitResult Wait(int64_t millis)
virtual ~MutexLocker()
Definition lockers.h:21
MutexLocker(Mutex *mutex)
Definition lockers.h:16
#define ASSERT(E)
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition globals.h:581