• Skip to content
  • Skip to link menu
KDE 4.0 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 <unistd.h>
00038 #include <stdio.h>
00039 #include <stdlib.h>
00040 #include <assert.h>
00041 }
00042 
00043 #include <QtCore/QMutex>
00044 #include <QtCore/QString>
00045 #include "threadweaver/threadweaver_export.h"
00046 
00047 namespace ThreadWeaver {
00048 
00049     extern THREADWEAVER_EXPORT bool Debug;
00050     extern THREADWEAVER_EXPORT int DebugLevel;
00051     extern THREADWEAVER_EXPORT QMutex GlobalMutex;
00052 
00056     extern inline void setDebugLevel (bool debug, int level);
00057 
00073     inline void debug(int severity, const char * cformat, ...)
00074 #ifdef __GNUC__
00075     __attribute__ ( (format (printf, 2, 3 ) ) )
00076 #endif
00077 ;
00078 
00080     inline void debug(bool condition, int severity, const char * cformat, ...)
00081 #ifdef __GNUC__
00082     __attribute__ ( (format (printf, 3, 4 ) ) )
00083 #endif
00084 ;
00085 
00086 
00089 #ifdef PROTECT
00090 #undef PROTECT
00091 #endif
00092 #define PROTECT(x) do { QMutexLocker l(&ThreadWeaver::GlobalMutex); (x); } while (0)
00093 
00095 #ifdef P_ASSERT
00096 #undef P_ASSERT
00097 #endif
00098 
00099 #define P_ASSERT(x) do { QMutexLocker l(&ThreadWeaver::GlobalMutex); Q_ASSERT(x); } while (0)
00100 
00101     inline void setDebugLevel (bool debug, int level)
00102     {
00103     Debug = debug;
00104     DebugLevel = level;
00105     }
00106 
00107 #ifndef QT_NO_DEBUG
00108     inline void debug(int severity, const char * cformat, ...)
00109     {
00110     if ( Debug == true && ( severity<=DebugLevel || severity == 0) )
00111     {
00112         QString text;
00113 
00114         va_list ap;
00115         va_start( ap, cformat );
00116         PROTECT (vprintf (cformat, ap));
00117         va_end (ap);
00118     }
00119     }
00120 
00121     inline void debug(bool condition, int severity, const char *cformat, ...)
00122     {
00123     if (condition && Debug == true && ( severity<=DebugLevel || severity == 0) )
00124     {
00125         QString text;
00126 
00127         va_list ap;
00128         va_start( ap, cformat );
00129         PROTECT (vprintf (cformat, ap));
00130         va_end (ap);
00131     }
00132     }
00133 #else
00134     inline void debug(int, const char *, ...) {}
00135     inline void debug(bool, int, const char *, ...) {}
00136 #endif
00137 
00138   inline bool invariant() { return true; }
00139 
00140 #define INVARIANT Q_ASSERT_X (invariant(), __FILE__, "class invariant failed" );
00141 
00142 #define REQUIRE(x) \
00143 INVARIANT \
00144 Q_ASSERT_X (x, Q_FUNC_INFO, "unfulfilled requirement " #x );
00145 
00146 #define ENSURE(x) \
00147 INVARIANT \
00148 Q_ASSERT_X (x, Q_FUNC_INFO, "broken guarantee " #x );
00149 
00150 
00151 #ifdef QT_NO_DEBUG
00152 #define DEBUGONLY(x)
00153 #else
00154 #define DEBUGONLY(x) x
00155 #endif
00156 
00157 }
00158 
00159 #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
  •   WTF
  • KJSEmbed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  •   core
  • Phonon
  •   Backend
  • 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