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