• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

ThreadWeaver

DebuggingAids.h

Go to the documentation of this file.
00001 /* -*- C++ -*-
00002 
00003    This file declares debugging aids for multithreaded applications.
00004 
00005    $ Author: Mirko Boehm $
00006    $ Copyright: (C) 2004, 2005 Mirko Boehm $
00007    $ Contact: mirko@kde.org
00008          http://www.kde.org
00009          http://www.hackerbuero.org $
00010 
00011    This library is free software; you can redistribute it and/or
00012    modify it under the terms of the GNU Library General Public
00013    License as published by the Free Software Foundation; either
00014    version 2 of the License, or (at your option) any later version.
00015 
00016    This library is distributed in the hope that it will be useful,
00017    but WITHOUT ANY WARRANTY; without even the implied warranty of
00018    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019    Library General Public License for more details.
00020 
00021    You should have received a copy of the GNU Library General Public License
00022    along with this library; see the file COPYING.LIB.  If not, write to
00023    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00024    Boston, MA 02110-1301, USA.
00025 
00026    $Id: DebuggingAids.h 30 2005-08-16 16:16:04Z mirko $
00027 */
00028 
00029 //krazy:excludeall=inline
00030 
00031 #ifndef DEBUGGINGAIDS_H
00032 #define DEBUGGINGAIDS_H
00033 
00034 extern "C"
00035 {
00036 #include <stdarg.h>
00037 #include <stdio.h>
00038 #include <stdlib.h>
00039 #include <assert.h>
00040 }
00041 
00042 #include <QtCore/QMutex>
00043 #include <QtCore/QString>
00044 #include "threadweaver/threadweaver_export.h"
00045 
00046 namespace ThreadWeaver {
00047 
00048     extern THREADWEAVER_EXPORT bool Debug;
00049     extern THREADWEAVER_EXPORT int DebugLevel;
00050     extern THREADWEAVER_EXPORT QMutex GlobalMutex;
00051 
00055     extern inline void setDebugLevel (bool debug, int level);
00056 
00072     inline void debug(int severity, const char * cformat, ...)
00073 #ifdef __GNUC__
00074     __attribute__ ( (format (printf, 2, 3 ) ) )
00075 #endif
00076 ;
00077 
00079     inline void debug(bool condition, int severity, const char * cformat, ...)
00080 #ifdef __GNUC__
00081     __attribute__ ( (format (printf, 3, 4 ) ) )
00082 #endif
00083 ;
00084 
00085 
00088 #ifdef PROTECT
00089 #undef PROTECT
00090 #endif
00091 #define PROTECT(x) do { QMutexLocker l(&ThreadWeaver::GlobalMutex); (x); } while (0)
00092 
00094 #ifdef P_ASSERT
00095 #undef P_ASSERT
00096 #endif
00097 
00098 #define P_ASSERT(x) do { QMutexLocker l(&ThreadWeaver::GlobalMutex); Q_ASSERT(x); } while (0)
00099 
00100     inline void setDebugLevel (bool debug, int level)
00101     {
00102     Debug = debug;
00103     DebugLevel = level;
00104     }
00105 
00106 #ifndef QT_NO_DEBUG
00107     inline void debug(int severity, const char * cformat, ...)
00108     {
00109     if ( Debug == true && ( severity<=DebugLevel || severity == 0) )
00110     {
00111         QString text;
00112 
00113         va_list ap;
00114         va_start( ap, cformat );
00115         PROTECT (vprintf (cformat, ap));
00116         va_end (ap);
00117     }
00118     }
00119 
00120     inline void debug(bool condition, int severity, const char *cformat, ...)
00121     {
00122     if (condition && Debug == true && ( severity<=DebugLevel || severity == 0) )
00123     {
00124         QString text;
00125 
00126         va_list ap;
00127         va_start( ap, cformat );
00128         PROTECT (vprintf (cformat, ap));
00129         va_end (ap);
00130     }
00131     }
00132 #else
00133     inline void debug(int, const char *, ...) {}
00134     inline void debug(bool, int, const char *, ...) {}
00135 #endif
00136 
00137   inline bool invariant() { return true; }
00138 
00139 #define INVARIANT Q_ASSERT_X (invariant(), __FILE__, "class invariant failed" );
00140 
00141 #define REQUIRE(x) \
00142 INVARIANT \
00143 Q_ASSERT_X (x, Q_FUNC_INFO, "unfulfilled requirement " #x );
00144 
00145 #define ENSURE(x) \
00146 INVARIANT \
00147 Q_ASSERT_X (x, Q_FUNC_INFO, "broken guarantee " #x );
00148 
00149 
00150 #ifdef QT_NO_DEBUG
00151 #define DEBUGONLY(x)
00152 #else
00153 #define DEBUGONLY(x) x
00154 #endif
00155 
00156 }
00157 
00158 #endif // DEBUGGINGAIDS_H

ThreadWeaver

Skip menu "ThreadWeaver"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal