2014-08-12 23:19:53 +00:00
|
|
|
// Copyright (c) 2012, 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.
|
|
|
|
|
2016-10-26 07:26:03 +00:00
|
|
|
#ifndef RUNTIME_BIN_LOCKERS_H_
|
|
|
|
#define RUNTIME_BIN_LOCKERS_H_
|
2014-08-12 23:19:53 +00:00
|
|
|
|
|
|
|
#include "bin/thread.h"
|
|
|
|
#include "platform/assert.h"
|
|
|
|
|
|
|
|
namespace dart {
|
|
|
|
namespace bin {
|
|
|
|
|
2016-11-04 19:30:56 +00:00
|
|
|
class MutexLocker {
|
2014-08-12 23:19:53 +00:00
|
|
|
public:
|
2014-08-14 00:06:04 +00:00
|
|
|
explicit MutexLocker(Mutex* mutex) : mutex_(mutex) {
|
2023-04-12 01:11:05 +00:00
|
|
|
ASSERT(mutex != nullptr);
|
2014-08-12 23:19:53 +00:00
|
|
|
mutex_->Lock();
|
|
|
|
}
|
|
|
|
|
2016-11-04 19:30:56 +00:00
|
|
|
virtual ~MutexLocker() { mutex_->Unlock(); }
|
2014-08-12 23:19:53 +00:00
|
|
|
|
|
|
|
private:
|
2014-08-14 00:06:04 +00:00
|
|
|
Mutex* const mutex_;
|
2014-08-12 23:19:53 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(MutexLocker);
|
|
|
|
};
|
|
|
|
|
|
|
|
class MonitorLocker {
|
|
|
|
public:
|
2014-08-14 00:06:04 +00:00
|
|
|
explicit MonitorLocker(Monitor* monitor) : monitor_(monitor) {
|
2023-04-12 01:11:05 +00:00
|
|
|
ASSERT(monitor != nullptr);
|
2014-08-12 23:19:53 +00:00
|
|
|
monitor_->Enter();
|
|
|
|
}
|
|
|
|
|
2016-11-04 19:30:56 +00:00
|
|
|
virtual ~MonitorLocker() { monitor_->Exit(); }
|
2014-08-12 23:19:53 +00:00
|
|
|
|
2014-08-14 00:06:04 +00:00
|
|
|
Monitor::WaitResult Wait(int64_t millis = Monitor::kNoTimeout) {
|
2014-08-12 23:19:53 +00:00
|
|
|
return monitor_->Wait(millis);
|
|
|
|
}
|
|
|
|
|
2016-11-04 19:30:56 +00:00
|
|
|
void Notify() { monitor_->Notify(); }
|
2014-08-12 23:19:53 +00:00
|
|
|
|
2016-11-04 19:30:56 +00:00
|
|
|
void NotifyAll() { monitor_->NotifyAll(); }
|
2014-08-12 23:19:53 +00:00
|
|
|
|
|
|
|
private:
|
2014-08-14 00:06:04 +00:00
|
|
|
Monitor* const monitor_;
|
2014-08-12 23:19:53 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(MonitorLocker);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace bin
|
|
|
|
} // namespace dart
|
|
|
|
|
2016-10-26 07:26:03 +00:00
|
|
|
#endif // RUNTIME_BIN_LOCKERS_H_
|