/[svn]/linuxsampler/trunk/src/common/Mutex.h
ViewVC logotype

Diff of /linuxsampler/trunk/src/common/Mutex.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3764 by schoenebeck, Fri Jun 23 12:24:58 2017 UTC revision 3765 by schoenebeck, Mon Apr 6 09:46:52 2020 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6   *   Copyright (C) 2005 - 2017 Christian Schoenebeck                       *   *   Copyright (C) 2005 - 2020 Christian Schoenebeck                       *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 24  Line 24 
24  #ifndef __MUTEX_H__  #ifndef __MUTEX_H__
25  #define __MUTEX_H__  #define __MUTEX_H__
26    
27    // enable this for detecting mutex misusage and for debugging dead locks
28    // (these features then still need to be enabled by Mutex::setDebugEnabled())
29    //#define DEBUG_MUTEX 1
30    
31  #if defined(WIN32)  #if defined(WIN32)
32  #include <windows.h>  #include <windows.h>
33  #else  #else
# Line 121  class Mutex { Line 125  class Mutex {
125           */           */
126          void Unlock();          void Unlock();
127    
128    #if DEBUG_MUTEX
129        /** @brief Enable bug detection and debugging features.
130         *
131         * By passing @c true to this method, bug detection and debugging features
132         * will be enabled for this Mutex object. For instance this will trigger an
133         * assertion fault if a thread attempts to Unlock() a thread it does not own
134         * a lock on, or when locking more than once while not using mutex type
135         * @c RECURSIVE and much more. Additionally this will also record the name
136         * of the thread currently holding a lock, and the backtrace of that
137         * thread's lock. The latter information can then be used to debug
138         * deadlocks.
139         *
140         * By default this is turned off and must be enabled for individual Mutex
141         * objects, because otherwise it would cause a large number of false
142         * positives (i.e. in certain edge cases like thread constructors /
143         * destructors for instance).
144         *
145         * @param b - whether to enable bug detection / debugging features
146         */
147        void setDebugEnabled(bool b) {
148            debugSelf = b;
149        }
150    #endif
151    
152      protected:      protected:
153      #if defined(WIN32)      #if defined(WIN32)
154          HANDLE hMutex;          HANDLE hMutex;
# Line 129  class Mutex { Line 157  class Mutex {
157          pthread_mutexattr_t __posix_mutexattr;          pthread_mutexattr_t __posix_mutexattr;
158      #endif      #endif
159          type_t type;          type_t type;
160        #if DEBUG_MUTEX
161            std::string owner; ///< Name of the thread owning the current lock.
162            long long int count; ///< How many times the owner currently acquired the lock recursively.
163            std::string backtrace; ///< Call stack trace of (last) lock.
164            bool debugSelf; ///< Whether bug detection and debugging features are enabled.
165        #endif
166  };  };
167    
168  // Lock guard for exception safe locking  // Lock guard for exception safe locking

Legend:
Removed from v.3764  
changed lines
  Added in v.3765

  ViewVC Help
Powered by ViewVC