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

ThreadWeaver

  • sources
  • kde-4.12
  • kdelibs
  • threadweaver
  • Weaver
DebuggingAids.h
Go to the documentation of this file.
1 /* -*- C++ -*-
2 
3  This file declares debugging aids for multithreaded applications.
4 
5  $ Author: Mirko Boehm $
6  $ Copyright: (C) 2004-2013 Mirko Boehm $
7  $ Contact: mirko@kde.org
8  http://www.kde.org
9  http://creative-destruction.me $
10 
11  This library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU Library General Public
13  License as published by the Free Software Foundation; either
14  version 2 of the License, or (at your option) any later version.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  Library General Public License for more details.
20 
21  You should have received a copy of the GNU Library General Public License
22  along with this library; see the file COPYING.LIB. If not, write to
23  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24  Boston, MA 02110-1301, USA.
25 
26  $Id: DebuggingAids.h 30 2005-08-16 16:16:04Z mirko $
27 */
28 
29 //krazy:excludeall=inline
30 
31 #ifndef DEBUGGINGAIDS_H
32 #define DEBUGGINGAIDS_H
33 
34 #include <QtCore/QtGlobal>
35 
36 extern "C"
37 {
38 #include <stdarg.h>
39 #ifndef Q_WS_WIN
40 #include <unistd.h>
41 #endif
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <assert.h>
45 }
46 
47 #include <QtCore/QMutex>
48 #include <QtCore/QString>
49 #include "threadweaver/threadweaver_export.h"
50 
51 namespace ThreadWeaver {
52 
53  extern THREADWEAVER_EXPORT bool Debug;
54  extern THREADWEAVER_EXPORT int DebugLevel;
55  extern THREADWEAVER_EXPORT QMutex GlobalMutex;
56 
60  extern inline void setDebugLevel (bool debug, int level);
61 
77  inline void debug(int severity, const char * cformat, ...)
78 #ifdef __GNUC__
79  __attribute__ ( (format (printf, 2, 3 ) ) )
80 #endif
81 ;
82 
84  inline void debug(bool condition, int severity, const char * cformat, ...)
85 #ifdef __GNUC__
86  __attribute__ ( (format (printf, 3, 4 ) ) )
87 #endif
88 ;
89 
90 
93 #ifdef PROTECT
94 #undef PROTECT
95 #endif
96 #define PROTECT(x) do { QMutexLocker l(&ThreadWeaver::GlobalMutex); (x); } while (0)
97 
99 #ifdef P_ASSERT
100 #undef P_ASSERT
101 #endif
102 
103 #define P_ASSERT(x) do { QMutexLocker l(&ThreadWeaver::GlobalMutex); Q_ASSERT(x); } while (0)
104 
105  inline void setDebugLevel (bool debug, int level)
106  {
107  Debug = debug;
108  DebugLevel = level;
109  }
110 
111 #ifndef QT_NO_DEBUG
112  inline void debug(int severity, const char * cformat, ...)
113  {
114  if ( Debug == true && ( severity<=DebugLevel || severity == 0) )
115  {
116  QString text;
117 
118  va_list ap;
119  va_start( ap, cformat );
120  PROTECT (vprintf (cformat, ap));
121  va_end (ap);
122  }
123  }
124 
125  inline void debug(bool condition, int severity, const char *cformat, ...)
126  {
127  if (condition && Debug == true && ( severity<=DebugLevel || severity == 0) )
128  {
129  QString text;
130 
131  va_list ap;
132  va_start( ap, cformat );
133  PROTECT (vprintf (cformat, ap));
134  va_end (ap);
135  }
136  }
137 #else
138  inline void debug(int, const char *, ...) {}
139  inline void debug(bool, int, const char *, ...) {}
140 #endif
141 
142  inline bool invariant() { return true; }
143 
144 #define INVARIANT Q_ASSERT_X (invariant(), __FILE__, "class invariant failed" );
145 
146 #define REQUIRE(x) \
147 INVARIANT \
148 Q_ASSERT_X (x, Q_FUNC_INFO, "unfulfilled requirement " #x );
149 
150 #define ENSURE(x) \
151 INVARIANT \
152 Q_ASSERT_X (x, Q_FUNC_INFO, "broken guarantee " #x );
153 
154 
155 #ifdef QT_NO_DEBUG
156 #define DEBUGONLY(x)
157 #else
158 #define DEBUGONLY(x) x
159 #endif
160 
161 }
162 
163 #endif // DEBUGGINGAIDS_H
ThreadWeaver::GlobalMutex
QMutex GlobalMutex
A global mutex for the ThreadWeaver objects.
Definition: DebuggingAids.cpp:37
PROTECT
#define PROTECT(x)
PROTECT executes x with GlobalMutex locked.
Definition: DebuggingAids.h:96
ThreadWeaver::setDebugLevel
void setDebugLevel(bool debug, int level)
Set the debug log level.
Definition: DebuggingAids.h:105
ThreadWeaver::debug
void debug(int severity, const char *cformat,...)
This method prints a text message on the screen, if debugging is enabled.
Definition: DebuggingAids.h:112
threadweaver_export.h
ThreadWeaver::invariant
bool invariant()
Definition: DebuggingAids.h:142
ThreadWeaver::DebugLevel
int DebugLevel
Definition: DebuggingAids.cpp:39
ThreadWeaver::Debug
bool Debug
Definition: DebuggingAids.cpp:38
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:53 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

ThreadWeaver

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal