diff options
author | Kate Stone <katherine.stone@apple.com> | 2016-09-06 20:57:50 +0000 |
---|---|---|
committer | Kate Stone <katherine.stone@apple.com> | 2016-09-06 20:57:50 +0000 |
commit | b9c1b51e45b845debb76d8658edabca70ca56079 (patch) | |
tree | dfcb5a13ef2b014202340f47036da383eaee74aa /lldb/tools/debugserver/source/PThreadMutex.h | |
parent | d5aa73376966339caad04013510626ec2e42c760 (diff) | |
download | llvm-b9c1b51e45b845debb76d8658edabca70ca56079.zip llvm-b9c1b51e45b845debb76d8658edabca70ca56079.tar.gz llvm-b9c1b51e45b845debb76d8658edabca70ca56079.tar.bz2 |
*** This commit represents a complete reformatting of the LLDB source code
*** to conform to clang-format’s LLVM style. This kind of mass change has
*** two obvious implications:
Firstly, merging this particular commit into a downstream fork may be a huge
effort. Alternatively, it may be worth merging all changes up to this commit,
performing the same reformatting operation locally, and then discarding the
merge for this particular commit. The commands used to accomplish this
reformatting were as follows (with current working directory as the root of
the repository):
find . \( -iname "*.c" -or -iname "*.cpp" -or -iname "*.h" -or -iname "*.mm" \) -exec clang-format -i {} +
find . -iname "*.py" -exec autopep8 --in-place --aggressive --aggressive {} + ;
The version of clang-format used was 3.9.0, and autopep8 was 1.2.4.
Secondly, “blame” style tools will generally point to this commit instead of
a meaningful prior commit. There are alternatives available that will attempt
to look through this change and find the appropriate prior commit. YMMV.
llvm-svn: 280751
Diffstat (limited to 'lldb/tools/debugserver/source/PThreadMutex.h')
-rw-r--r-- | lldb/tools/debugserver/source/PThreadMutex.h | 178 |
1 files changed, 75 insertions, 103 deletions
diff --git a/lldb/tools/debugserver/source/PThreadMutex.h b/lldb/tools/debugserver/source/PThreadMutex.h index 9a12f6e..c6ec293 100644 --- a/lldb/tools/debugserver/source/PThreadMutex.h +++ b/lldb/tools/debugserver/source/PThreadMutex.h @@ -14,135 +14,107 @@ #ifndef __PThreadMutex_h__ #define __PThreadMutex_h__ -#include <pthread.h> #include <assert.h> +#include <pthread.h> #include <stdint.h> //#define DEBUG_PTHREAD_MUTEX_DEADLOCKS 1 -#if defined (DEBUG_PTHREAD_MUTEX_DEADLOCKS) -#define PTHREAD_MUTEX_LOCKER(var, mutex) PThreadMutex::Locker var(mutex, __FUNCTION__, __FILE__, __LINE__) +#if defined(DEBUG_PTHREAD_MUTEX_DEADLOCKS) +#define PTHREAD_MUTEX_LOCKER(var, mutex) \ + PThreadMutex::Locker var(mutex, __FUNCTION__, __FILE__, __LINE__) #else #define PTHREAD_MUTEX_LOCKER(var, mutex) PThreadMutex::Locker var(mutex) #endif -class PThreadMutex -{ +class PThreadMutex { public: - - class Locker - { - public: -#if defined (DEBUG_PTHREAD_MUTEX_DEADLOCKS) - - Locker(PThreadMutex& m, const char *function, const char *file, int line); - Locker(PThreadMutex* m, const char *function, const char *file, int line); - Locker(pthread_mutex_t *mutex, const char *function, const char *file, int line); - ~Locker(); - void Lock(); - void Unlock(); + class Locker { + public: +#if defined(DEBUG_PTHREAD_MUTEX_DEADLOCKS) + + Locker(PThreadMutex &m, const char *function, const char *file, int line); + Locker(PThreadMutex *m, const char *function, const char *file, int line); + Locker(pthread_mutex_t *mutex, const char *function, const char *file, + int line); + ~Locker(); + void Lock(); + void Unlock(); #else - Locker(PThreadMutex& m) : - m_pMutex(m.Mutex()) - { - Lock(); - } - - Locker(PThreadMutex* m) : - m_pMutex(m ? m->Mutex() : NULL) - { - Lock(); - } - - Locker(pthread_mutex_t *mutex) : - m_pMutex(mutex) - { - Lock(); - } - - void Lock() - { - if (m_pMutex) - ::pthread_mutex_lock (m_pMutex); - } - - void Unlock() - { - if (m_pMutex) - ::pthread_mutex_unlock (m_pMutex); - } - - ~Locker() - { - Unlock(); - } + Locker(PThreadMutex &m) : m_pMutex(m.Mutex()) { Lock(); } -#endif - - // unlock any the current mutex and lock the new one if it is valid - void Reset(pthread_mutex_t *pMutex = NULL) - { - Unlock(); - m_pMutex = pMutex; - Lock(); - } - pthread_mutex_t *m_pMutex; -#if defined (DEBUG_PTHREAD_MUTEX_DEADLOCKS) - const char *m_function; - const char *m_file; - int m_line; - uint64_t m_lock_time; -#endif - }; + Locker(PThreadMutex *m) : m_pMutex(m ? m->Mutex() : NULL) { Lock(); } + Locker(pthread_mutex_t *mutex) : m_pMutex(mutex) { Lock(); } - PThreadMutex() - { - int err; - err = ::pthread_mutex_init (&m_mutex, NULL); assert(err == 0); + void Lock() { + if (m_pMutex) + ::pthread_mutex_lock(m_pMutex); } - PThreadMutex(int type) - { - int err; - ::pthread_mutexattr_t attr; - err = ::pthread_mutexattr_init (&attr); assert(err == 0); - err = ::pthread_mutexattr_settype (&attr, type); assert(err == 0); - err = ::pthread_mutex_init (&m_mutex, &attr); assert(err == 0); - err = ::pthread_mutexattr_destroy (&attr); assert(err == 0); + void Unlock() { + if (m_pMutex) + ::pthread_mutex_unlock(m_pMutex); } - ~PThreadMutex() - { - int err; - err = ::pthread_mutex_destroy (&m_mutex); - if (err != 0) - { - err = Unlock(); - if (err == 0) - ::pthread_mutex_destroy (&m_mutex); - } - } + ~Locker() { Unlock(); } - pthread_mutex_t *Mutex() - { - return &m_mutex; - } +#endif - int Lock() - { - return ::pthread_mutex_lock (&m_mutex); + // unlock any the current mutex and lock the new one if it is valid + void Reset(pthread_mutex_t *pMutex = NULL) { + Unlock(); + m_pMutex = pMutex; + Lock(); } - - int Unlock() - { - return ::pthread_mutex_unlock (&m_mutex); + pthread_mutex_t *m_pMutex; +#if defined(DEBUG_PTHREAD_MUTEX_DEADLOCKS) + const char *m_function; + const char *m_file; + int m_line; + uint64_t m_lock_time; +#endif + }; + + PThreadMutex() { + int err; + err = ::pthread_mutex_init(&m_mutex, NULL); + assert(err == 0); + } + + PThreadMutex(int type) { + int err; + ::pthread_mutexattr_t attr; + err = ::pthread_mutexattr_init(&attr); + assert(err == 0); + err = ::pthread_mutexattr_settype(&attr, type); + assert(err == 0); + err = ::pthread_mutex_init(&m_mutex, &attr); + assert(err == 0); + err = ::pthread_mutexattr_destroy(&attr); + assert(err == 0); + } + + ~PThreadMutex() { + int err; + err = ::pthread_mutex_destroy(&m_mutex); + if (err != 0) { + err = Unlock(); + if (err == 0) + ::pthread_mutex_destroy(&m_mutex); } + } + + pthread_mutex_t *Mutex() { return &m_mutex; } + + int Lock() { return ::pthread_mutex_lock(&m_mutex); } + + int Unlock() { return ::pthread_mutex_unlock(&m_mutex); } protected: - pthread_mutex_t m_mutex; + pthread_mutex_t m_mutex; }; #endif |