src/dbus/qdbusthreaddebug_p.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtDBus module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    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 #if !defined(QDBUS_THREAD_DEBUG) && defined(QT_BUILD_INTERNAL)
       
    56 # define QDBUS_THREAD_DEBUG 1
       
    57 #endif
       
    58 
       
    59 #if QDBUS_THREAD_DEBUG
       
    60 QT_BEGIN_NAMESPACE
       
    61 typedef void (*qdbusThreadDebugFunc)(int, int, QDBusConnectionPrivate *);
       
    62 QDBUS_EXPORT void qdbusDefaultThreadDebug(int, int, QDBusConnectionPrivate *);
       
    63 extern QDBUS_EXPORT qdbusThreadDebugFunc qdbusThreadDebug;
       
    64 QT_END_NAMESPACE
       
    65 #endif
       
    66 
       
    67 enum ThreadAction {
       
    68     ConnectAction = 0,
       
    69     DisconnectAction = 1,
       
    70     RegisterObjectAction = 2,
       
    71     UnregisterObjectAction = 3,
       
    72     ObjectRegisteredAtAction = 4,
       
    73 
       
    74     CloseConnectionAction = 10,
       
    75     ObjectDestroyedAction = 11,
       
    76     RelaySignalAction = 12,
       
    77     HandleObjectCallAction = 13,
       
    78     HandleSignalAction = 14,
       
    79     ConnectRelayAction = 15,
       
    80     DisconnectRelayAction = 16,
       
    81     FindMetaObject1Action = 17,
       
    82     FindMetaObject2Action = 18,
       
    83     RegisterServiceAction = 19,
       
    84     UnregisterServiceAction = 20,
       
    85     UpdateSignalHookOwnerAction = 21,
       
    86     HandleObjectCallPostEventAction = 22,
       
    87     HandleObjectCallSemaphoreAction = 23,
       
    88     DoDispatchAction = 24,
       
    89     SendWithReplyAsyncAction = 25,
       
    90     MessageResultReceivedAction = 26,
       
    91     ActivateSignalAction = 27,
       
    92     PendingCallBlockAction = 28,
       
    93 
       
    94     AddTimeoutAction = 50,
       
    95     RealAddTimeoutAction = 51,
       
    96     RemoveTimeoutAction = 52,
       
    97     KillTimerAction = 58,
       
    98     TimerEventAction = 59,
       
    99     AddWatchAction = 60,
       
   100     RemoveWatchAction = 61,
       
   101     ToggleWatchAction = 62,
       
   102     SocketReadAction = 63,
       
   103     SocketWriteAction = 64
       
   104 };
       
   105 
       
   106 struct QDBusLockerBase
       
   107 {
       
   108     enum Condition
       
   109     {
       
   110         BeforeLock,
       
   111         AfterLock,
       
   112         BeforeUnlock,
       
   113         AfterUnlock,
       
   114 
       
   115         BeforePost,
       
   116         AfterPost,
       
   117         BeforeDeliver,
       
   118         AfterDeliver,
       
   119 
       
   120         BeforeAcquire,
       
   121         AfterAcquire,
       
   122         BeforeRelease,
       
   123         AfterRelease
       
   124     };
       
   125 
       
   126 #if QDBUS_THREAD_DEBUG
       
   127     static inline void reportThreadAction(int action, int condition, QDBusConnectionPrivate *ptr)
       
   128     { if (qdbusThreadDebug) qdbusThreadDebug(action, condition, ptr); }
       
   129 #else
       
   130     static inline void reportThreadAction(int, int, QDBusConnectionPrivate *) { }
       
   131 #endif
       
   132 };
       
   133 
       
   134 struct QDBusReadLocker: QDBusLockerBase
       
   135 {
       
   136     QDBusConnectionPrivate *self;
       
   137     ThreadAction action;
       
   138     inline QDBusReadLocker(ThreadAction a, QDBusConnectionPrivate *s)
       
   139         : self(s), action(a)
       
   140     {
       
   141         reportThreadAction(action, BeforeLock, self);
       
   142         self->lock.lockForRead();
       
   143         reportThreadAction(action, AfterLock, self);
       
   144     }
       
   145 
       
   146     inline ~QDBusReadLocker()
       
   147     {
       
   148         reportThreadAction(action, BeforeUnlock, self);
       
   149         self->lock.unlock();
       
   150         reportThreadAction(action, AfterUnlock, self);
       
   151     }
       
   152 };
       
   153 
       
   154 struct QDBusWriteLocker: QDBusLockerBase
       
   155 {
       
   156     QDBusConnectionPrivate *self;
       
   157     ThreadAction action;
       
   158     inline QDBusWriteLocker(ThreadAction a, QDBusConnectionPrivate *s)
       
   159         : self(s), action(a)
       
   160     {
       
   161         reportThreadAction(action, BeforeLock, self);
       
   162         self->lock.lockForWrite();
       
   163         reportThreadAction(action, AfterLock, self);
       
   164     }
       
   165 
       
   166     inline ~QDBusWriteLocker()
       
   167     {
       
   168         reportThreadAction(action, BeforeUnlock, self);
       
   169         self->lock.unlock();
       
   170         reportThreadAction(action, AfterUnlock, self);
       
   171     }
       
   172 };
       
   173 
       
   174 struct QDBusMutexLocker: QDBusLockerBase
       
   175 {
       
   176     QDBusConnectionPrivate *self;
       
   177     QMutex *mutex;
       
   178     ThreadAction action;
       
   179     inline QDBusMutexLocker(ThreadAction a, QDBusConnectionPrivate *s,
       
   180                             QMutex *m)
       
   181         : self(s), mutex(m), action(a)
       
   182     {
       
   183         reportThreadAction(action, BeforeLock, self);
       
   184         mutex->lock();
       
   185         reportThreadAction(action, AfterLock, self);
       
   186     }
       
   187 
       
   188     inline ~QDBusMutexLocker()
       
   189     {
       
   190         reportThreadAction(action, BeforeUnlock, self);
       
   191         mutex->unlock();
       
   192         reportThreadAction(action, AfterUnlock, self);
       
   193     }
       
   194 };
       
   195 
       
   196 struct QDBusDispatchLocker: QDBusMutexLocker
       
   197 {
       
   198     inline QDBusDispatchLocker(ThreadAction a, QDBusConnectionPrivate *s)
       
   199         : QDBusMutexLocker(a, s, &s->dispatchLock)
       
   200     { }
       
   201 };
       
   202 
       
   203 struct QDBusWatchAndTimeoutLocker: QDBusMutexLocker
       
   204 {
       
   205     inline QDBusWatchAndTimeoutLocker(ThreadAction a, QDBusConnectionPrivate *s)
       
   206         : QDBusMutexLocker(a, s, &s->watchAndTimeoutLock)
       
   207     { }
       
   208 };
       
   209 
       
   210 #if QDBUS_THREAD_DEBUG
       
   211 # define SEM_ACQUIRE(action, sem)                                       \
       
   212     do {                                                                \
       
   213     QDBusLockerBase::reportThreadAction(action, QDBusLockerBase::BeforeAcquire, this); \
       
   214     sem.acquire();                                                      \
       
   215     QDBusLockerBase::reportThreadAction(action, QDBusLockerBase::AfterAcquire, this); \
       
   216     } while (0)
       
   217 
       
   218 # define SEM_RELEASE(action, sem)                                       \
       
   219     do {                                                                \
       
   220     QDBusLockerBase::reportThreadAction(action, QDBusLockerBase::BeforeRelease, that); \
       
   221     sem.release();                                                      \
       
   222     QDBusLockerBase::reportThreadAction(action, QDBusLockerBase::AfterRelease, that); \
       
   223     } while (0)
       
   224 
       
   225 #else
       
   226 # define SEM_ACQUIRE(action, sem)       sem.acquire()
       
   227 # define SEM_RELEASE(action, sem)       sem.release()
       
   228 #endif
       
   229 
       
   230 #endif