1 /* 2 * Copyright (C) 2007-2016 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 /* 18 * Some OS specific dribs and drabs (locking etc). 19 */ 20 21 #if !defined(_WIN32) 22 #include <pthread.h> 23 #endif 24 25 #include "logger.h" 26 27 #if !defined(_WIN32) 28 static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER; 29 #endif 30 __android_log_lock()31LIBLOG_HIDDEN void __android_log_lock() 32 { 33 #if !defined(_WIN32) 34 /* 35 * If we trigger a signal handler in the middle of locked activity and the 36 * signal handler logs a message, we could get into a deadlock state. 37 */ 38 pthread_mutex_lock(&log_init_lock); 39 #endif 40 } 41 __android_log_trylock()42LIBLOG_HIDDEN int __android_log_trylock() 43 { 44 #if !defined(_WIN32) 45 return pthread_mutex_trylock(&log_init_lock); 46 #else 47 return 0; 48 #endif 49 } 50 __android_log_unlock()51LIBLOG_HIDDEN void __android_log_unlock() 52 { 53 #if !defined(_WIN32) 54 pthread_mutex_unlock(&log_init_lock); 55 #endif 56 } 57