dnxDebug.h

Go to the documentation of this file.
00001 /*--------------------------------------------------------------------------
00002 
00003    Copyright (c) 2006-2007, Intellectual Reserve, Inc. All rights reserved.
00004 
00005    This program is free software; you can redistribute it and/or modify
00006    it under the terms of the GNU General Public License version 2 as
00007    published by the Free Software Foundation.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012    GNU General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with this program; if not, write to the Free Software
00016    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018   --------------------------------------------------------------------------*/
00019 
00028 #ifndef _DNXDEBUG_H_
00029 #define _DNXDEBUG_H_
00030 
00031 #include "dnxLogging.h"
00032 
00033 #include <errno.h>
00034 #include <string.h>
00035 #include <pthread.h>
00036 #include <assert.h>
00037 
00038 #if HAVE_CONFIG_H
00039 # include <config.h>
00040 #endif
00041 
00042 #if DEBUG_LOCKS && defined(PTHREAD_MUTEX_ERRORCHECK_NP)
00043 extern int pthread_mutexattr_settype(pthread_mutexattr_t * attr, int kind);
00044 # define DNX_PT_MUTEX_INIT(mp) { \
00045       pthread_mutexattr_t attr; \
00046       pthread_mutexattr_init(&attr); \
00047       pthread_mutex_init((mp),&attr); \
00048       pthread_mutexattr_settype((mp), PTHREAD_MUTEX_ERRORCHECK_NP); \
00049       pthread_mutexattr_destroy(&attr); \
00050       dnxDebug(2, "mutex INIT at %s:%d", __FILE__, __LINE__); \
00051    }
00052 # define DNX_PT_MUTEX_DESTROY(mp) \
00053    dnxDebug(2, "mutex DESTROY at %s:%d", __FILE__, __LINE__); \
00054    if (pthread_mutex_destroy(mp) != 0) { \
00055       dnxDebug(1, "mutex_destroy: mutex is in use at %s:%d!", __FILE__, __LINE__); \
00056       assert(0); \
00057    }
00058 # define DNX_PT_MUTEX_LOCK(mp) \
00059    dnxDebug(10, "mutex LOCK at %s:%d", __FILE__, __LINE__); \
00060    if (pthread_mutex_lock(mp) != 0) { \
00061       switch (errno) { \
00062       case EINVAL:   dnxDebug(1, "mutex_lock: mutex is not initialized at %s:%d!", __FILE__, __LINE__); break; \
00063       case EDEADLK:  dnxDebug(1, "mutex_lock: mutex already locked by this thread at %s:%d!", __FILE__, __LINE__); break; \
00064       default:       dnxDebug(1, "mutex_lock: unknown error %d: %s at %s:%d!", errno, strerror(errno), __FILE__, __LINE__); break; \
00065       } assert(0); \
00066    }
00067 # define DNX_PT_MUTEX_UNLOCK(mp) \
00068    dnxDebug(10, "mutex UNLOCK at %s:%d", __FILE__, __LINE__); \
00069    if (pthread_mutex_unlock(mp) != 0) { \
00070       switch (errno) { \
00071       case EINVAL:   dnxDebug(1, "mutex_unlock: mutex is not initialized at %s:%d!", __FILE__, __LINE__); break; \
00072       case EPERM:    dnxDebug(1, "mutex_unlock: mutex not locked by this thread at %s:%d!", __FILE__, __LINE__); break; \
00073       default:       dnxDebug(1, "mutex_unlock: unknown error %d: %s at %s:%d!", errno, strerror(errno), __FILE__, __LINE__); break; \
00074       } assert(0); \
00075    }
00076 #else    /* !DEBUG_LOCKS || !?PTHREAD_MUTEX_ERRORCHECK_NP */
00077 # define DNX_PT_MUTEX_INIT(mp)      pthread_mutex_init((mp),0)
00078 # define DNX_PT_MUTEX_DESTROY(mp)   pthread_mutex_destroy(mp)
00079 # define DNX_PT_MUTEX_LOCK(mp)      pthread_mutex_lock(mp)
00080 # define DNX_PT_MUTEX_UNLOCK(mp)    pthread_mutex_unlock(mp)
00081 #endif   /* DEBUG && ?PTRHEAD_MUTEX_ERRORCHECK_NP */
00082 
00083 #if DEBUG_LOCKS
00084 # define DNX_PT_COND_DESTROY(cvp) \
00085    if (pthread_cond_destroy(cvp) != 0) { \
00086       dnxDebug(1, "cond_destroy: condition-variable is in use at %s:%d!", __FILE__, __LINE__); \
00087       assert(0); \
00088    }
00089 #else    /* !DEBUG_LOCKS */
00090 # define DNX_PT_COND_DESTROY(cvp)   pthread_cond_destroy(cvp)
00091 #endif   /* ?DEBUG */
00092 
00093 #if DEBUG_HEAP
00094 # include "dnxHeap.h"
00095 # define xmalloc(sz)    dnxMalloc((sz), __FILE__, __LINE__)
00096 # define xcalloc(n,sz)  dnxCalloc((n), (sz), __FILE__, __LINE__)
00097 # define xrealloc(p,sz) dnxRealloc((p), (sz), __FILE__, __LINE__)
00098 # define xstrdup(str)   dnxStrdup((str), __FILE__, __LINE__)
00099 # define xfree          dnxFree
00100 # define xheapchk       dnxCheckHeap
00101 #else
00102 # include <stdlib.h>
00103 # include <string.h>
00104 # define xmalloc        malloc
00105 # define xcalloc        calloc
00106 # define xrealloc       realloc
00107 # define xstrdup        strdup
00108 # define xfree          free
00109 # define xheapchk()
00110 #endif
00111 
00112 #endif   /* !?_DNXDEBUG_H_ */
00113 

Generated on Tue Apr 13 15:48:07 2010 for DNX by  doxygen 1.5.6