blob: d08206aafbf47f058d11cd9b3b21bee3fbdff862 [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;
Sebastien Hertz138dbfc2013-12-04 18:15:25 +010025Mutex* Locks::deoptimization_lock_ = NULL;
Ian Rogers1bf8d4d2013-05-30 00:18:49 -070026ReaderWriterMutex* Locks::classlinker_classes_lock_ = NULL;
Ian Rogers81d425b2012-09-27 16:03:43 -070027ReaderWriterMutex* Locks::heap_bitmap_lock_ = NULL;
Ian Rogers81d425b2012-09-27 16:03:43 -070028Mutex* Locks::logging_lock_ = NULL;
Ian Rogers120f1c72012-09-28 17:17:10 -070029ReaderWriterMutex* Locks::mutator_lock_ = NULL;
30Mutex* Locks::runtime_shutdown_lock_ = NULL;
31Mutex* Locks::thread_list_lock_ = NULL;
Ian Rogers81d425b2012-09-27 16:03:43 -070032Mutex* Locks::thread_suspend_count_lock_ = NULL;
Ian Rogers62d6c772013-02-27 08:32:07 -080033Mutex* Locks::trace_lock_ = NULL;
Dave Allison0aded082013-11-07 13:15:11 -080034Mutex* Locks::profiler_lock_ = NULL;
Ian Rogers120f1c72012-09-28 17:17:10 -070035Mutex* Locks::unexpected_signal_lock_ = NULL;
Ian Rogers81d425b2012-09-27 16:03:43 -070036
37void Locks::Init() {
38 if (logging_lock_ != NULL) {
39 // Already initialized.
Ian Rogers120f1c72012-09-28 17:17:10 -070040 DCHECK(abort_lock_ != NULL);
jeffhao09bfc6a2012-12-11 18:11:43 -080041 DCHECK(breakpoint_lock_ != NULL);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +010042 DCHECK(deoptimization_lock_ != NULL);
Ian Rogers81d425b2012-09-27 16:03:43 -070043 DCHECK(classlinker_classes_lock_ != NULL);
44 DCHECK(heap_bitmap_lock_ != NULL);
Ian Rogers81d425b2012-09-27 16:03:43 -070045 DCHECK(logging_lock_ != NULL);
Ian Rogers120f1c72012-09-28 17:17:10 -070046 DCHECK(mutator_lock_ != NULL);
47 DCHECK(thread_list_lock_ != NULL);
Ian Rogers81d425b2012-09-27 16:03:43 -070048 DCHECK(thread_suspend_count_lock_ != NULL);
Ian Rogers62d6c772013-02-27 08:32:07 -080049 DCHECK(trace_lock_ != NULL);
Dave Allison0aded082013-11-07 13:15:11 -080050 DCHECK(profiler_lock_ != NULL);
Ian Rogers120f1c72012-09-28 17:17:10 -070051 DCHECK(unexpected_signal_lock_ != NULL);
Ian Rogers81d425b2012-09-27 16:03:43 -070052 } else {
53 logging_lock_ = new Mutex("logging lock", kLoggingLock, true);
54 abort_lock_ = new Mutex("abort lock", kAbortLock, true);
Ian Rogers120f1c72012-09-28 17:17:10 -070055
jeffhao09bfc6a2012-12-11 18:11:43 -080056 DCHECK(breakpoint_lock_ == NULL);
57 breakpoint_lock_ = new Mutex("breakpoint lock", kBreakpointLock);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +010058 DCHECK(deoptimization_lock_ == NULL);
59 deoptimization_lock_ = new Mutex("deoptimization lock", kDeoptimizationLock);
Ian Rogers81d425b2012-09-27 16:03:43 -070060 DCHECK(classlinker_classes_lock_ == NULL);
Ian Rogers1bf8d4d2013-05-30 00:18:49 -070061 classlinker_classes_lock_ = new ReaderWriterMutex("ClassLinker classes lock",
62 kClassLinkerClassesLock);
Ian Rogers81d425b2012-09-27 16:03:43 -070063 DCHECK(heap_bitmap_lock_ == NULL);
64 heap_bitmap_lock_ = new ReaderWriterMutex("heap bitmap lock", kHeapBitmapLock);
Ian Rogers120f1c72012-09-28 17:17:10 -070065 DCHECK(mutator_lock_ == NULL);
66 mutator_lock_ = new ReaderWriterMutex("mutator lock", kMutatorLock);
67 DCHECK(runtime_shutdown_lock_ == NULL);
68 runtime_shutdown_lock_ = new Mutex("runtime shutdown lock", kRuntimeShutdownLock);
69 DCHECK(thread_list_lock_ == NULL);
70 thread_list_lock_ = new Mutex("thread list lock", kThreadListLock);
Ian Rogers81d425b2012-09-27 16:03:43 -070071 DCHECK(thread_suspend_count_lock_ == NULL);
72 thread_suspend_count_lock_ = new Mutex("thread suspend count lock", kThreadSuspendCountLock);
Ian Rogers62d6c772013-02-27 08:32:07 -080073 DCHECK(trace_lock_ == NULL);
74 trace_lock_ = new Mutex("trace lock", kTraceLock);
Dave Allison0aded082013-11-07 13:15:11 -080075 DCHECK(profiler_lock_ == NULL);
76 profiler_lock_ = new Mutex("profiler lock", kProfilerLock);
Ian Rogers120f1c72012-09-28 17:17:10 -070077 DCHECK(unexpected_signal_lock_ == NULL);
78 unexpected_signal_lock_ = new Mutex("unexpected signal lock", kUnexpectedSignalLock, true);
Ian Rogers81d425b2012-09-27 16:03:43 -070079 }
80}
81
82} // namespace art