diff --git a/runtime/bin/eventhandler_win.h b/runtime/bin/eventhandler_win.h index 0e91158dea5..9f54c6e9a90 100644 --- a/runtime/bin/eventhandler_win.h +++ b/runtime/bin/eventhandler_win.h @@ -16,6 +16,7 @@ #include #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 diff --git a/runtime/bin/lockers.h b/runtime/bin/lockers.h index e87031581cb..6f8fa5b24c4 100644 --- a/runtime/bin/lockers.h +++ b/runtime/bin/lockers.h @@ -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 diff --git a/runtime/platform/lockers.h b/runtime/platform/lockers.h new file mode 100644 index 00000000000..df0cf59f438 --- /dev/null +++ b/runtime/platform/lockers.h @@ -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_ diff --git a/runtime/platform/platform_sources.gni b/runtime/platform/platform_sources.gni index 19fa38e1359..0e0c12dd75c 100644 --- a/runtime/platform/platform_sources.gni +++ b/runtime/platform/platform_sources.gni @@ -18,6 +18,7 @@ platform_sources = [ "growable_array.h", "hashmap.cc", "hashmap.h", + "lockers.h", "memory_sanitizer.h", "safe_stack.h", "signal_blocker.h",