[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
R=kustermann@google.com

Change-Id: I975f24a8499ea85d0ba887180a81287fcf4101bb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/405460
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
This commit is contained in:
Vyacheslav Egorov
2025-01-23 04:19:48 -08:00
committed by Commit Queue
parent b0813fb9e2
commit 939cdfbfcd
4 changed files with 60 additions and 39 deletions
+1 -1
View File
@@ -16,6 +16,7 @@
#include <utility>
#include "bin/builtin.h"
#include "bin/lockers.h"
#include "bin/reference_counting.h"
#include "bin/socket_base.h"
#include "bin/thread.h"
@@ -29,7 +30,6 @@ class EventHandlerImplementation;
class FileHandle;
class Handle;
class ListenSocket;
class MonitorLocker;
class SocketHandle;
// An OverlappedBuffer encapsulates the OVERLAPPED structure and the
+3 -38
View File
@@ -5,49 +5,14 @@
#ifndef RUNTIME_BIN_LOCKERS_H_
#define RUNTIME_BIN_LOCKERS_H_
#include "bin/thread.h"
#include "platform/assert.h"
#include "platform/lockers.h"
namespace dart {
namespace bin {
class MutexLocker {
public:
explicit MutexLocker(Mutex* mutex) : mutex_(mutex) {
ASSERT(mutex != nullptr);
mutex_->Lock();
}
virtual ~MutexLocker() { mutex_->Unlock(); }
private:
Mutex* const mutex_;
DISALLOW_COPY_AND_ASSIGN(MutexLocker);
};
class MonitorLocker {
public:
explicit MonitorLocker(Monitor* monitor) : monitor_(monitor) {
ASSERT(monitor != nullptr);
monitor_->Enter();
}
virtual ~MonitorLocker() { monitor_->Exit(); }
Monitor::WaitResult Wait(int64_t millis = Monitor::kNoTimeout) {
return monitor_->Wait(millis);
}
void Notify() { monitor_->Notify(); }
void NotifyAll() { monitor_->NotifyAll(); }
private:
Monitor* const monitor_;
DISALLOW_COPY_AND_ASSIGN(MonitorLocker);
};
using MutexLocker = dart::platform::MutexLocker;
using MonitorLocker = dart::platform::MonitorLocker;
} // namespace bin
} // namespace dart
+55
View File
@@ -0,0 +1,55 @@
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#ifndef RUNTIME_PLATFORM_LOCKERS_H_
#define RUNTIME_PLATFORM_LOCKERS_H_
#include "platform/assert.h"
#include "platform/synchronization.h"
namespace dart {
namespace platform {
class MutexLocker {
public:
explicit MutexLocker(Mutex* mutex) : mutex_(mutex) {
ASSERT(mutex != nullptr);
mutex_->Lock();
}
virtual ~MutexLocker() { mutex_->Unlock(); }
private:
Mutex* const mutex_;
DISALLOW_COPY_AND_ASSIGN(MutexLocker);
};
class MonitorLocker {
public:
explicit MonitorLocker(Monitor* monitor) : monitor_(monitor) {
ASSERT(monitor != nullptr);
monitor_->Enter();
}
virtual ~MonitorLocker() { monitor_->Exit(); }
Monitor::WaitResult Wait(int64_t millis = Monitor::kNoTimeout) {
return monitor_->Wait(millis);
}
void Notify() { monitor_->Notify(); }
void NotifyAll() { monitor_->NotifyAll(); }
private:
Monitor* const monitor_;
DISALLOW_COPY_AND_ASSIGN(MonitorLocker);
};
} // namespace platform
} // namespace dart
#endif // RUNTIME_PLATFORM_LOCKERS_H_
+1
View File
@@ -18,6 +18,7 @@ platform_sources = [
"growable_array.h",
"hashmap.cc",
"hashmap.h",
"lockers.h",
"memory_sanitizer.h",
"safe_stack.h",
"signal_blocker.h",