1 /*
2  * Copyright (C) 2023 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 <audio_utils/mutex.h>
18 
19 #define LOG_TAG "audio_utils::mutex"
20 #include <utils/Log.h>
21 
22 #include <com_android_media_audioserver.h>
23 
24 namespace android::audio_utils {
25 
mutex_get_enable_flag()26 bool mutex_get_enable_flag() {
27     static const bool enable = []() {
28         const bool flag = com::android::media::audioserver::mutex_priority_inheritance();
29         ALOGD("get_enable_flag: mutex_priority_inheritance: %s", flag ? "true" : "false");
30         return flag;
31     }();
32     return enable;
33 }
34 
35 // Define mutex::get_mutex_stat_array here because header-only ODR inline linking
36 // results in multiple objects if included into multiple shared libraries.
37 template<>
get_mutex_stat_array()38 mutex::stat_array_t& mutex::get_mutex_stat_array() {
39     [[clang::no_destroy]] static constinit stat_array_t stat_array{};
40     return stat_array;
41 }
42 
43 // Define mutex::get_registry here because header-only ODR inline linking
44 // results in multiple objects if included into multiple shared libraries.
45 template<>
get_registry()46 mutex::thread_registry_t& mutex::get_registry() {
47     [[clang::no_destroy]] static thread_registry_t thread_registry{};
48     return thread_registry;
49 }
50 
51 }  // namespace android::audio_utils
52