Skip to content

Commit 939cdfb

Browse files
mralephCommit Queue
authored andcommitted
[vm] Move bin/lockers.h to platform/lockers.h
We have to place these classes into a platform namespace to avoid conflicts with vm/lockers.h. To avoid changes to files in bin we simply change bin/lockers.h to introduce bin::{Monitor,Mutex}Locker aliases for platform::{Monitor,Mutex}Locker. TEST=ci [email protected] Change-Id: I975f24a8499ea85d0ba887180a81287fcf4101bb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/405460 Reviewed-by: Martin Kustermann <[email protected]> Commit-Queue: Slava Egorov <[email protected]>
1 parent b0813fb commit 939cdfb

File tree

4 files changed

+60
-39
lines changed

4 files changed

+60
-39
lines changed

runtime/bin/eventhandler_win.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <utility>
1717

1818
#include "bin/builtin.h"
19+
#include "bin/lockers.h"
1920
#include "bin/reference_counting.h"
2021
#include "bin/socket_base.h"
2122
#include "bin/thread.h"
@@ -29,7 +30,6 @@ class EventHandlerImplementation;
2930
class FileHandle;
3031
class Handle;
3132
class ListenSocket;
32-
class MonitorLocker;
3333
class SocketHandle;
3434

3535
// An OverlappedBuffer encapsulates the OVERLAPPED structure and the

runtime/bin/lockers.h

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,14 @@
55
#ifndef RUNTIME_BIN_LOCKERS_H_
66
#define RUNTIME_BIN_LOCKERS_H_
77

8-
#include "bin/thread.h"
98
#include "platform/assert.h"
9+
#include "platform/lockers.h"
1010

1111
namespace dart {
1212
namespace bin {
1313

14-
class MutexLocker {
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-
26-
DISALLOW_COPY_AND_ASSIGN(MutexLocker);
27-
};
28-
29-
class MonitorLocker {
30-
public:
31-
explicit MonitorLocker(Monitor* monitor) : monitor_(monitor) {
32-
ASSERT(monitor != nullptr);
33-
monitor_->Enter();
34-
}
35-
36-
virtual ~MonitorLocker() { monitor_->Exit(); }
37-
38-
Monitor::WaitResult Wait(int64_t millis = Monitor::kNoTimeout) {
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-
49-
DISALLOW_COPY_AND_ASSIGN(MonitorLocker);
50-
};
14+
using MutexLocker = dart::platform::MutexLocker;
15+
using MonitorLocker = dart::platform::MonitorLocker;
5116

5217
} // namespace bin
5318
} // namespace dart

runtime/platform/lockers.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) 2025, 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_PLATFORM_LOCKERS_H_
6+
#define RUNTIME_PLATFORM_LOCKERS_H_
7+
8+
#include "platform/assert.h"
9+
#include "platform/synchronization.h"
10+
11+
namespace dart {
12+
namespace platform {
13+
14+
class MutexLocker {
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+
26+
DISALLOW_COPY_AND_ASSIGN(MutexLocker);
27+
};
28+
29+
class MonitorLocker {
30+
public:
31+
explicit MonitorLocker(Monitor* monitor) : monitor_(monitor) {
32+
ASSERT(monitor != nullptr);
33+
monitor_->Enter();
34+
}
35+
36+
virtual ~MonitorLocker() { monitor_->Exit(); }
37+
38+
Monitor::WaitResult Wait(int64_t millis = Monitor::kNoTimeout) {
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+
49+
DISALLOW_COPY_AND_ASSIGN(MonitorLocker);
50+
};
51+
52+
} // namespace platform
53+
} // namespace dart
54+
55+
#endif // RUNTIME_PLATFORM_LOCKERS_H_

runtime/platform/platform_sources.gni

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ platform_sources = [
1818
"growable_array.h",
1919
"hashmap.cc",
2020
"hashmap.h",
21+
"lockers.h",
2122
"memory_sanitizer.h",
2223
"safe_stack.h",
2324
"signal_blocker.h",

0 commit comments

Comments
 (0)