blob: 51a40c383a633cc3e4befcfa46bd81311660dbbc [file] [log] [blame]
Ian Rogers81d425b2012-09-27 16:03:43 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17#include "locks.h"
18
Elliott Hughes76b61672012-12-12 17:47:30 -080019#include "base/mutex.h"
Ian Rogers81d425b2012-09-27 16:03:43 -070020
21namespace art {
22
Ian Rogers120f1c72012-09-28 17:17:10 -070023Mutex* Locks::abort_lock_ = NULL;
jeffhao09bfc6a2012-12-11 18:11:43 -080024Mutex* Locks::breakpoint_lock_ = NULL;
Ian Rogers1bf8d4d2013-05-30 00:18:49 -070025ReaderWriterMutex* Locks::classlinker_classes_lock_ = NULL;
Ian Rogers81d425b2012-09-27 16:03:43 -070026ReaderWriterMutex* Locks::heap_bitmap_lock_ = NULL;
Ian Rogers81d425b2012-09-27 16:03:43 -070027Mutex* Locks::logging_lock_ = NULL;
Ian Rogers120f1c72012-09-28 17:17:10 -070028ReaderWriterMutex* Locks::mutator_lock_ = NULL;
29Mutex* Locks::runtime_shutdown_lock_ = NULL;
30Mutex* Locks::thread_list_lock_ = NULL;
Ian Rogers81d425b2012-09-27 16:03:43 -070031Mutex* Locks::thread_suspend_count_lock_ = NULL;
Ian Rogers62d6c772013-02-27 08:32:07 -080032Mutex* Locks::trace_lock_ = NULL;
Ian Rogers120f1c72012-09-28 17:17:10 -070033Mutex* Locks::unexpected_signal_lock_ = NULL;
Ian Rogers81d425b2012-09-27 16:03:43 -070034
35void Locks::Init() {
36 if (logging_lock_ != NULL) {
37 // Already initialized.
Ian Rogers120f1c72012-09-28 17:17:10 -070038 DCHECK(abort_lock_ != NULL);
jeffhao09bfc6a2012-12-11 18:11:43 -080039 DCHECK(breakpoint_lock_ != NULL);
Ian Rogers81d425b2012-09-27 16:03:43 -070040 DCHECK(classlinker_classes_lock_ != NULL);
41 DCHECK(heap_bitmap_lock_ != NULL);
Ian Rogers81d425b2012-09-27 16:03:43 -070042 DCHECK(logging_lock_ != NULL);
Ian Rogers120f1c72012-09-28 17:17:10 -070043 DCHECK(mutator_lock_ != NULL);
44 DCHECK(thread_list_lock_ != NULL);
Ian Rogers81d425b2012-09-27 16:03:43 -070045 DCHECK(thread_suspend_count_lock_ != NULL);
Ian Rogers62d6c772013-02-27 08:32:07 -080046 DCHECK(trace_lock_ != NULL);
Ian Rogers120f1c72012-09-28 17:17:10 -070047 DCHECK(unexpected_signal_lock_ != NULL);
Ian Rogers81d425b2012-09-27 16:03:43 -070048 } else {
49 logging_lock_ = new Mutex("logging lock", kLoggingLock, true);
50 abort_lock_ = new Mutex("abort lock", kAbortLock, true);
Ian Rogers120f1c72012-09-28 17:17:10 -070051
jeffhao09bfc6a2012-12-11 18:11:43 -080052 DCHECK(breakpoint_lock_ == NULL);
53 breakpoint_lock_ = new Mutex("breakpoint lock", kBreakpointLock);
Ian Rogers81d425b2012-09-27 16:03:43 -070054 DCHECK(classlinker_classes_lock_ == NULL);
Ian Rogers1bf8d4d2013-05-30 00:18:49 -070055 classlinker_classes_lock_ = new ReaderWriterMutex("ClassLinker classes lock",
56 kClassLinkerClassesLock);
Ian Rogers81d425b2012-09-27 16:03:43 -070057 DCHECK(heap_bitmap_lock_ == NULL);
58 heap_bitmap_lock_ = new ReaderWriterMutex("heap bitmap lock", kHeapBitmapLock);
Ian Rogers120f1c72012-09-28 17:17:10 -070059 DCHECK(mutator_lock_ == NULL);
60 mutator_lock_ = new ReaderWriterMutex("mutator lock", kMutatorLock);
61 DCHECK(runtime_shutdown_lock_ == NULL);
62 runtime_shutdown_lock_ = new Mutex("runtime shutdown lock", kRuntimeShutdownLock);
63 DCHECK(thread_list_lock_ == NULL);
64 thread_list_lock_ = new Mutex("thread list lock", kThreadListLock);
Ian Rogers81d425b2012-09-27 16:03:43 -070065 DCHECK(thread_suspend_count_lock_ == NULL);
66 thread_suspend_count_lock_ = new Mutex("thread suspend count lock", kThreadSuspendCountLock);
Ian Rogers62d6c772013-02-27 08:32:07 -080067 DCHECK(trace_lock_ == NULL);
68 trace_lock_ = new Mutex("trace lock", kTraceLock);
Ian Rogers120f1c72012-09-28 17:17:10 -070069 DCHECK(unexpected_signal_lock_ == NULL);
70 unexpected_signal_lock_ = new Mutex("unexpected signal lock", kUnexpectedSignalLock, true);
Ian Rogers81d425b2012-09-27 16:03:43 -070071 }
72}
73
74} // namespace art