2 * Copyright (C) 2011 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "object_lock.h"
19 #include "mirror/object-inl.h"
25 ObjectLock<T>::ObjectLock(Thread* self, Handle<T> object) : self_(self), obj_(object) {
26 CHECK(object.Get() != nullptr);
27 obj_->MonitorEnter(self_);
31 ObjectLock<T>::~ObjectLock() {
32 obj_->MonitorExit(self_);
36 void ObjectLock<T>::WaitIgnoringInterrupts() {
37 Monitor::Wait(self_, obj_.Get(), 0, 0, false, kWaiting);
41 void ObjectLock<T>::Notify() {
46 void ObjectLock<T>::NotifyAll() {
47 obj_->NotifyAll(self_);
51 ObjectTryLock<T>::ObjectTryLock(Thread* self, Handle<T> object) : self_(self), obj_(object) {
52 CHECK(object.Get() != nullptr);
53 acquired_ = obj_->MonitorTryEnter(self_) != nullptr;
57 ObjectTryLock<T>::~ObjectTryLock() {
59 obj_->MonitorExit(self_);
63 template class ObjectLock<mirror::Class>;
64 template class ObjectLock<mirror::Object>;
65 template class ObjectTryLock<mirror::Class>;
66 template class ObjectTryLock<mirror::Object>;