Move QScopedLoopLevelCounter to qthread_p.h
authorBradley T. Hughes <bradley.hughes@nokia.com>
Mon, 21 Nov 2011 14:28:57 +0000 (15:28 +0100)
committerQt by Nokia <qt-info@nokia.com>
Thu, 24 Nov 2011 14:06:31 +0000 (15:06 +0100)
... and use it in QCoreApplication::notifyInterna() instead of
"reinventing" the wheel there. The constructor and destructor for
QScopedLoopLevelCounter are inline, so the class does not need to be
exported.

Change-Id: I7af5a4ef0987f277bcc50c1057f3c74152f3d79d
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
src/corelib/kernel/qcoreapplication.cpp
src/corelib/thread/qthread_p.h
src/widgets/kernel/qapplication_p.h

index c30f613..2a80d39 100644 (file)
@@ -809,16 +809,7 @@ bool QCoreApplication::notifyInternal(QObject *receiver, QEvent *event)
     // call overhead.
     QObjectPrivate *d = receiver->d_func();
     QThreadData *threadData = d->threadData;
-
-    // Exception-safety without try/catch
-    struct Incrementer {
-        int &variable;
-        inline Incrementer(int &variable) : variable(variable)
-        { ++variable; }
-        inline ~Incrementer()
-        { --variable; }
-    };
-    Incrementer inc(threadData->loopLevel);
+    QScopedLoopLevelCounter loopLevelCounter(threadData);
 
 #ifdef QT_JAMBI_BUILD
     int deleteWatch = 0;
index 04f9bf2..66dd8db 100644 (file)
@@ -227,6 +227,17 @@ public:
     bool isAdopted;
 };
 
+class QScopedLoopLevelCounter
+{
+    QThreadData *threadData;
+public:
+    inline QScopedLoopLevelCounter(QThreadData *threadData)
+        : threadData(threadData)
+    { ++threadData->loopLevel; }
+    inline ~QScopedLoopLevelCounter()
+    { --threadData->loopLevel; }
+};
+
 // thread wrapper for the main() thread
 class QAdoptedThread : public QThread
 {
index d0674d4..c353a29 100644 (file)
@@ -68,7 +68,6 @@
 #include "QtCore/qhash.h"
 #include "QtCore/qpointer.h"
 #include "private/qcoreapplication_p.h"
-#include <private/qthread_p.h>
 #include "QtCore/qpoint.h"
 #include <QTime>
 #include <QWindowSystemInterface>
@@ -263,17 +262,6 @@ typedef struct tagGESTURECONFIG
 
 #endif // Q_WS_WIN
 
-class QScopedLoopLevelCounter
-{
-    QThreadData *threadData;
-public:
-    QScopedLoopLevelCounter(QThreadData *threadData)
-        : threadData(threadData)
-    { ++threadData->loopLevel; }
-    ~QScopedLoopLevelCounter()
-    { --threadData->loopLevel; }
-};
-
 struct FontHash : public QHash<QByteArray, QFont>
 {
     FontHash();