Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 1 | /* |
| 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 Hughes | 76b6167 | 2012-12-12 17:47:30 -0800 | [diff] [blame] | 19 | #include "base/mutex.h" |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 20 | |
| 21 | namespace art { |
| 22 | |
Ian Rogers | 120f1c7 | 2012-09-28 17:17:10 -0700 | [diff] [blame] | 23 | Mutex* Locks::abort_lock_ = NULL; |
jeffhao | 09bfc6a | 2012-12-11 18:11:43 -0800 | [diff] [blame] | 24 | Mutex* Locks::breakpoint_lock_ = NULL; |
Ian Rogers | 1bf8d4d | 2013-05-30 00:18:49 -0700 | [diff] [blame] | 25 | ReaderWriterMutex* Locks::classlinker_classes_lock_ = NULL; |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 26 | ReaderWriterMutex* Locks::heap_bitmap_lock_ = NULL; |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 27 | Mutex* Locks::logging_lock_ = NULL; |
Ian Rogers | 120f1c7 | 2012-09-28 17:17:10 -0700 | [diff] [blame] | 28 | ReaderWriterMutex* Locks::mutator_lock_ = NULL; |
| 29 | Mutex* Locks::runtime_shutdown_lock_ = NULL; |
| 30 | Mutex* Locks::thread_list_lock_ = NULL; |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 31 | Mutex* Locks::thread_suspend_count_lock_ = NULL; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 32 | Mutex* Locks::trace_lock_ = NULL; |
Ian Rogers | 120f1c7 | 2012-09-28 17:17:10 -0700 | [diff] [blame] | 33 | Mutex* Locks::unexpected_signal_lock_ = NULL; |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 34 | |
| 35 | void Locks::Init() { |
| 36 | if (logging_lock_ != NULL) { |
| 37 | // Already initialized. |
Ian Rogers | 120f1c7 | 2012-09-28 17:17:10 -0700 | [diff] [blame] | 38 | DCHECK(abort_lock_ != NULL); |
jeffhao | 09bfc6a | 2012-12-11 18:11:43 -0800 | [diff] [blame] | 39 | DCHECK(breakpoint_lock_ != NULL); |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 40 | DCHECK(classlinker_classes_lock_ != NULL); |
| 41 | DCHECK(heap_bitmap_lock_ != NULL); |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 42 | DCHECK(logging_lock_ != NULL); |
Ian Rogers | 120f1c7 | 2012-09-28 17:17:10 -0700 | [diff] [blame] | 43 | DCHECK(mutator_lock_ != NULL); |
| 44 | DCHECK(thread_list_lock_ != NULL); |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 45 | DCHECK(thread_suspend_count_lock_ != NULL); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 46 | DCHECK(trace_lock_ != NULL); |
Ian Rogers | 120f1c7 | 2012-09-28 17:17:10 -0700 | [diff] [blame] | 47 | DCHECK(unexpected_signal_lock_ != NULL); |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 48 | } else { |
| 49 | logging_lock_ = new Mutex("logging lock", kLoggingLock, true); |
| 50 | abort_lock_ = new Mutex("abort lock", kAbortLock, true); |
Ian Rogers | 120f1c7 | 2012-09-28 17:17:10 -0700 | [diff] [blame] | 51 | |
jeffhao | 09bfc6a | 2012-12-11 18:11:43 -0800 | [diff] [blame] | 52 | DCHECK(breakpoint_lock_ == NULL); |
| 53 | breakpoint_lock_ = new Mutex("breakpoint lock", kBreakpointLock); |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 54 | DCHECK(classlinker_classes_lock_ == NULL); |
Ian Rogers | 1bf8d4d | 2013-05-30 00:18:49 -0700 | [diff] [blame] | 55 | classlinker_classes_lock_ = new ReaderWriterMutex("ClassLinker classes lock", |
| 56 | kClassLinkerClassesLock); |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 57 | DCHECK(heap_bitmap_lock_ == NULL); |
| 58 | heap_bitmap_lock_ = new ReaderWriterMutex("heap bitmap lock", kHeapBitmapLock); |
Ian Rogers | 120f1c7 | 2012-09-28 17:17:10 -0700 | [diff] [blame] | 59 | 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 Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 65 | DCHECK(thread_suspend_count_lock_ == NULL); |
| 66 | thread_suspend_count_lock_ = new Mutex("thread suspend count lock", kThreadSuspendCountLock); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 67 | DCHECK(trace_lock_ == NULL); |
| 68 | trace_lock_ = new Mutex("trace lock", kTraceLock); |
Ian Rogers | 120f1c7 | 2012-09-28 17:17:10 -0700 | [diff] [blame] | 69 | DCHECK(unexpected_signal_lock_ == NULL); |
| 70 | unexpected_signal_lock_ = new Mutex("unexpected signal lock", kUnexpectedSignalLock, true); |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | |
| 74 | } // namespace art |