Reorder the members in QThreadData to avoid padding holes

Before this change, this struct had size 104 and a total of 21 padding
bytes. Now it's down to 88 bytes and only 5 bytes of padding.

pahole report on a 64-bit system:
    class QAtomicInt          _ref;                  /*     0     4 */
    /* XXX 4 bytes hole, try to pack */
public:
    class QThread *            thread;               /*     8     8 */
    HANDLE                     threadId;             /*    16     8 */
    bool                       quitNow;              /*    24     1 */
    /* XXX 3 bytes hole, try to pack */
    int                        loopLevel;            /*    28     4 */
    class QAtomicPointer<QAbstractEventDispatcher> eventDispatcher; /*    32     8 */
    class QStack<QEventLoop*> eventLoops;            /*    40     8 */
    /* --- cacheline 1 boundary (64 bytes) --- */
    class QPostEventList      postEventList;         /*    48    32 */
    bool                       canWait;              /*    80     1 */
    /* XXX 7 bytes hole, try to pack */
    class QVector<void*>      tls;                   /*    88     8 */
    bool                       isAdopted;            /*    96     1 */
    /* size: 104, cachelines: 2, members: 11 */
    /* sum members: 90, holes: 3, sum holes: 14 */
    /* padding: 7 */

Change-Id: I1fc88e0b312f38eccdea440734fd37e0519285a2
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
Thiago Macieira 2013-09-27 19:40:24 -07:00 committed by The Qt Project
parent 4533cc9944
commit 583d05863e
2 changed files with 14 additions and 10 deletions

View File

@ -58,8 +58,8 @@ QT_BEGIN_NAMESPACE
*/
QThreadData::QThreadData(int initialRefCount)
: _ref(initialRefCount), thread(0), threadId(0),
quitNow(false), loopLevel(0), eventDispatcher(0), canWait(true), isAdopted(false)
: _ref(initialRefCount), loopLevel(0), thread(0), threadId(0),
eventDispatcher(0), quitNow(false), canWait(true), isAdopted(false)
{
// fprintf(stderr, "QThreadData %p created\n", this);
}

View File

@ -219,8 +219,6 @@ public:
class QThreadData
{
QAtomicInt _ref;
public:
QThreadData(int initialRefCount = 1);
~QThreadData();
@ -262,17 +260,23 @@ public:
{ return std::find(locations, locations + Count, method) != locations + Count; }
};
QThread *thread;
Qt::HANDLE threadId;
bool quitNow;
private:
QAtomicInt _ref;
public:
int loopLevel;
QAtomicPointer<QAbstractEventDispatcher> eventDispatcher;
QStack<QEventLoop *> eventLoops;
QPostEventList postEventList;
bool canWait;
QThread *thread;
Qt::HANDLE threadId;
QAtomicPointer<QAbstractEventDispatcher> eventDispatcher;
QVector<void *> tls;
bool isAdopted;
FlaggedDebugSignatures flaggedSignatures;
bool quitNow;
bool canWait;
bool isAdopted;
};
class QScopedLoopLevelCounter