Qt 4.8
qdbusthreaddebug_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDBus module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 #ifndef QDBUSTHREADDEBUG_P_H
42 #define QDBUSTHREADDEBUG_P_H
43 
44 //
45 // W A R N I N G
46 // -------------
47 //
48 // This file is not part of the Qt API. It exists purely as an
49 // implementation detail. This header file may change from version to
50 // version without notice, or even be removed.
51 //
52 // We mean it.
53 //
54 
55 #include <QtCore/qglobal.h>
56 
57 #ifndef QT_NO_DBUS
58 
59 #if !defined(QDBUS_THREAD_DEBUG) && defined(QT_BUILD_INTERNAL)
60 # define QDBUS_THREAD_DEBUG 1
61 #endif
62 
63 #if QDBUS_THREAD_DEBUG
65 typedef void (*qdbusThreadDebugFunc)(int, int, QDBusConnectionPrivate *);
66 Q_DBUS_EXPORT void qdbusDefaultThreadDebug(int, int, QDBusConnectionPrivate *);
67 extern Q_DBUS_EXPORT qdbusThreadDebugFunc qdbusThreadDebug;
69 #endif
70 
77 
97 
108 };
109 
111 {
113  {
118 
123 
128  };
129 
130 #if QDBUS_THREAD_DEBUG
131  static inline void reportThreadAction(int action, int condition, QDBusConnectionPrivate *ptr)
132  { if (qdbusThreadDebug) qdbusThreadDebug(action, condition, ptr); }
133 #else
134  static inline void reportThreadAction(int, int, QDBusConnectionPrivate *) { }
135 #endif
136 };
137 
139 {
143  : self(s), action(a)
144  {
145  reportThreadAction(action, BeforeLock, self);
146  self->lock.lockForRead();
147  reportThreadAction(action, AfterLock, self);
148  }
149 
151  {
152  reportThreadAction(action, BeforeUnlock, self);
153  self->lock.unlock();
154  reportThreadAction(action, AfterUnlock, self);
155  }
156 };
157 
159 {
163  : self(s), action(a)
164  {
165  reportThreadAction(action, BeforeLock, self);
166  self->lock.lockForWrite();
167  reportThreadAction(action, AfterLock, self);
168  }
169 
171  {
172  reportThreadAction(action, BeforeUnlock, self);
173  self->lock.unlock();
174  reportThreadAction(action, AfterUnlock, self);
175  }
176 };
177 
179 {
184  QMutex *m)
185  : self(s), mutex(m), action(a)
186  {
187  reportThreadAction(action, BeforeLock, self);
188  mutex->lock();
189  reportThreadAction(action, AfterLock, self);
190  }
191 
193  {
194  reportThreadAction(action, BeforeUnlock, self);
195  mutex->unlock();
196  reportThreadAction(action, AfterUnlock, self);
197  }
198 };
199 
201 {
203  : QDBusMutexLocker(a, s, &s->dispatchLock)
204  { }
205 };
206 
208 {
210  : QDBusMutexLocker(a, s, &s->watchAndTimeoutLock)
211  { }
212 };
213 
214 #if QDBUS_THREAD_DEBUG
215 # define SEM_ACQUIRE(action, sem) \
216  do { \
217  QDBusLockerBase::reportThreadAction(action, QDBusLockerBase::BeforeAcquire, this); \
218  sem.acquire(); \
219  QDBusLockerBase::reportThreadAction(action, QDBusLockerBase::AfterAcquire, this); \
220  } while (0)
221 
222 # define SEM_RELEASE(action, sem) \
223  do { \
224  QDBusLockerBase::reportThreadAction(action, QDBusLockerBase::BeforeRelease, that); \
225  sem.release(); \
226  QDBusLockerBase::reportThreadAction(action, QDBusLockerBase::AfterRelease, that); \
227  } while (0)
228 
229 #else
230 # define SEM_ACQUIRE(action, sem) sem.acquire()
231 # define SEM_RELEASE(action, sem) sem.release()
232 #endif
233 
234 #endif // QT_NO_DBUS
235 #endif
QDBusWatchAndTimeoutLocker(ThreadAction a, QDBusConnectionPrivate *s)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void lock()
Locks the mutex.
Definition: qmutex.cpp:151
The QMutex class provides access serialization between threads.
Definition: qmutex.h:60
long ASN1_INTEGER_get ASN1_INTEGER * a
QDBusReadLocker(ThreadAction a, QDBusConnectionPrivate *s)
QDBusMutexLocker(ThreadAction a, QDBusConnectionPrivate *s, QMutex *m)
QDBusWriteLocker(ThreadAction a, QDBusConnectionPrivate *s)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QDBusDispatchLocker(ThreadAction a, QDBusConnectionPrivate *s)
const T * ptr(const T &t)
void unlock()
Unlocks the mutex.
Definition: qmutex.cpp:296
#define Q_DBUS_EXPORT
Definition: qglobal.h:1463
ThreadAction
static void reportThreadAction(int, int, QDBusConnectionPrivate *)