diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2016-01-06 20:12:03 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2016-01-06 20:12:03 +0000 |
commit | 9e6d35490a6542f9c97607f93c2ef8ca8e03cbcc (patch) | |
tree | dd2a1ddf0476664c2b823409c36cbccd52662ca7 /tools/debugserver/source/PThreadMutex.cpp | |
parent | 3bd2e91faeb9eeec1aae82c64a3253afff551cfd (diff) | |
download | src-vendor/lldb/lldb-trunk-r256945.tar.gz src-vendor/lldb/lldb-trunk-r256945.zip |
Vendor import of lldb trunk r256945:vendor/lldb/lldb-trunk-r256945
Diffstat (limited to 'tools/debugserver/source/PThreadMutex.cpp')
-rw-r--r-- | tools/debugserver/source/PThreadMutex.cpp | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/tools/debugserver/source/PThreadMutex.cpp b/tools/debugserver/source/PThreadMutex.cpp new file mode 100644 index 000000000000..bd91ed0154b1 --- /dev/null +++ b/tools/debugserver/source/PThreadMutex.cpp @@ -0,0 +1,84 @@ +//===-- PThreadMutex.cpp ----------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Created by Greg Clayton on 12/9/08. +// +//===----------------------------------------------------------------------===// + +#include "PThreadMutex.h" + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "DNBTimer.h" + +#if defined (DEBUG_PTHREAD_MUTEX_DEADLOCKS) + +PThreadMutex::Locker::Locker(PThreadMutex& m, const char *function, const char *file, const int line) : + m_pMutex(m.Mutex()), + m_function(function), + m_file(file), + m_line(line), + m_lock_time(0) +{ + Lock(); +} + +PThreadMutex::Locker::Locker(PThreadMutex* m, const char *function, const char *file, const int line) : + m_pMutex(m ? m->Mutex() : NULL), + m_function(function), + m_file(file), + m_line(line), + m_lock_time(0) +{ + Lock(); +} + +PThreadMutex::Locker::Locker(pthread_mutex_t *mutex, const char *function, const char *file, const int line) : + m_pMutex(mutex), + m_function(function), + m_file(file), + m_line(line), + m_lock_time(0) +{ + Lock(); +} + + +PThreadMutex::Locker::~Locker() +{ + Unlock(); +} + + +void +PThreadMutex::Locker::Lock() +{ + if (m_pMutex) + { + m_lock_time = DNBTimer::GetTimeOfDay(); + if (::pthread_mutex_trylock (m_pMutex) != 0) + { + fprintf(stdout, "::pthread_mutex_trylock (%8.8p) mutex is locked (function %s in %s:%i), waiting...\n", m_pMutex, m_function, m_file, m_line); + ::pthread_mutex_lock (m_pMutex); + fprintf(stdout, "::pthread_mutex_lock (%8.8p) succeeded after %6llu usecs (function %s in %s:%i)\n", m_pMutex, DNBTimer::GetTimeOfDay() - m_lock_time, m_function, m_file, m_line); + } + } +} + + +void +PThreadMutex::Locker::Unlock() +{ + fprintf(stdout, "::pthread_mutex_unlock (%8.8p) had lock for %6llu usecs in %s in %s:%i\n", m_pMutex, DNBTimer::GetTimeOfDay() - m_lock_time, m_function, m_file, m_line); + ::pthread_mutex_unlock (m_pMutex); +} + +#endif |