blob: 27b9d4bf96bcdc476920c0553e9d02f20128fd2a [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 Rogers81d425b2012-09-27 16:03:43 -070025Mutex* Locks::classlinker_classes_lock_ = NULL;
26ReaderWriterMutex* 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 Rogers120f1c72012-09-28 17:17:10 -070032Mutex* Locks::unexpected_signal_lock_ = NULL;
Ian Rogers81d425b2012-09-27 16:03:43 -070033
34void Locks::Init() {
35 if (logging_lock_ != NULL) {
36 // Already initialized.
Ian Rogers120f1c72012-09-28 17:17:10 -070037 DCHECK(abort_lock_ != NULL);
jeffhao09bfc6a2012-12-11 18:11:43 -080038 DCHECK(breakpoint_lock_ != NULL);
Ian Rogers81d425b2012-09-27 16:03:43 -070039 DCHECK(classlinker_classes_lock_ != NULL);
40 DCHECK(heap_bitmap_lock_ != NULL);
Ian Rogers81d425b2012-09-27 16:03:43 -070041 DCHECK(logging_lock_ != NULL);
Ian Rogers120f1c72012-09-28 17:17:10 -070042 DCHECK(mutator_lock_ != NULL);
43 DCHECK(thread_list_lock_ != NULL);
Ian Rogers81d425b2012-09-27 16:03:43 -070044 DCHECK(thread_suspend_count_lock_ != NULL);
Ian Rogers120f1c72012-09-28 17:17:10 -070045 DCHECK(unexpected_signal_lock_ != NULL);
Ian Rogers81d425b2012-09-27 16:03:43 -070046 } else {
47 logging_lock_ = new Mutex("logging lock", kLoggingLock, true);
48 abort_lock_ = new Mutex("abort lock", kAbortLock, true);
Ian Rogers120f1c72012-09-28 17:17:10 -070049
jeffhao09bfc6a2012-12-11 18:11:43 -080050 DCHECK(breakpoint_lock_ == NULL);
51 breakpoint_lock_ = new Mutex("breakpoint lock", kBreakpointLock);
Ian Rogers81d425b2012-09-27 16:03:43 -070052 DCHECK(classlinker_classes_lock_ == NULL);
53 classlinker_classes_lock_ = new Mutex("ClassLinker classes lock", kClassLinkerClassesLock);
54 DCHECK(heap_bitmap_lock_ == NULL);
55 heap_bitmap_lock_ = new ReaderWriterMutex("heap bitmap lock", kHeapBitmapLock);
Ian Rogers120f1c72012-09-28 17:17:10 -070056 DCHECK(mutator_lock_ == NULL);
57 mutator_lock_ = new ReaderWriterMutex("mutator lock", kMutatorLock);
58 DCHECK(runtime_shutdown_lock_ == NULL);
59 runtime_shutdown_lock_ = new Mutex("runtime shutdown lock", kRuntimeShutdownLock);
60 DCHECK(thread_list_lock_ == NULL);
61 thread_list_lock_ = new Mutex("thread list lock", kThreadListLock);
Ian Rogers81d425b2012-09-27 16:03:43 -070062 DCHECK(thread_suspend_count_lock_ == NULL);
63 thread_suspend_count_lock_ = new Mutex("thread suspend count lock", kThreadSuspendCountLock);
Ian Rogers120f1c72012-09-28 17:17:10 -070064 DCHECK(unexpected_signal_lock_ == NULL);
65 unexpected_signal_lock_ = new Mutex("unexpected signal lock", kUnexpectedSignalLock, true);
Ian Rogers81d425b2012-09-27 16:03:43 -070066 }
67}
68
69} // namespace art