[sanitizer] Improve FreeBSD ASLR detection
[llvm-project.git] / lldb / tools / debugserver / source / PThreadMutex.cpp
blob118921aee5a817c20973a327b63f2fd2295723f4
1 //===-- PThreadMutex.cpp ----------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Created by Greg Clayton on 12/9/08.
11 //===----------------------------------------------------------------------===//
13 #include "PThreadMutex.h"
15 #include "DNBTimer.h"
17 #if defined(DEBUG_PTHREAD_MUTEX_DEADLOCKS)
19 PThreadMutex::Locker::Locker(PThreadMutex &m, const char *function,
20 const char *file, const int line)
21 : m_pMutex(m.Mutex()), m_function(function), m_file(file), m_line(line),
22 m_lock_time(0) {
23 Lock();
26 PThreadMutex::Locker::Locker(PThreadMutex *m, const char *function,
27 const char *file, const int line)
28 : m_pMutex(m ? m->Mutex() : NULL), m_function(function), m_file(file),
29 m_line(line), m_lock_time(0) {
30 Lock();
33 PThreadMutex::Locker::Locker(pthread_mutex_t *mutex, const char *function,
34 const char *file, const int line)
35 : m_pMutex(mutex), m_function(function), m_file(file), m_line(line),
36 m_lock_time(0) {
37 Lock();
40 PThreadMutex::Locker::~Locker() { Unlock(); }
42 void PThreadMutex::Locker::Lock() {
43 if (m_pMutex) {
44 m_lock_time = DNBTimer::GetTimeOfDay();
45 if (::pthread_mutex_trylock(m_pMutex) != 0) {
46 fprintf(stdout, "::pthread_mutex_trylock (%8.8p) mutex is locked "
47 "(function %s in %s:%i), waiting...\n",
48 m_pMutex, m_function, m_file, m_line);
49 ::pthread_mutex_lock(m_pMutex);
50 fprintf(stdout, "::pthread_mutex_lock (%8.8p) succeeded after %6llu "
51 "usecs (function %s in %s:%i)\n",
52 m_pMutex, DNBTimer::GetTimeOfDay() - m_lock_time, m_function,
53 m_file, m_line);
58 void PThreadMutex::Locker::Unlock() {
59 fprintf(stdout, "::pthread_mutex_unlock (%8.8p) had lock for %6llu usecs in "
60 "%s in %s:%i\n",
61 m_pMutex, DNBTimer::GetTimeOfDay() - m_lock_time, m_function, m_file,
62 m_line);
63 ::pthread_mutex_unlock(m_pMutex);
66 #endif