Qt 4.8
Classes | Public Functions | Static Public Functions | Public Variables | Properties | List of all members
QThreadData Class Reference

#include <qthread_p.h>

Classes

class  FlaggedDebugSignatures
 

Public Functions

bool canWaitLocked ()
 
void deref ()
 
 QThreadData (int initialRefCount=1)
 
void ref ()
 
 ~QThreadData ()
 

Static Public Functions

static void clearCurrentThreadData ()
 
static QThreadDatacurrent ()
 
static QThreadDataget2 (QThread *thread)
 

Public Variables

bool canWait
 
QAbstractEventDispatchereventDispatcher
 
QStack< QEventLoop * > eventLoops
 
FlaggedDebugSignatures flaggedSignatures
 
bool isAdopted
 
int loopLevel
 
QPostEventList postEventList
 
bool quitNow
 
QThreadthread
 
Qt::HANDLE threadId
 
QVector< void * > tls
 

Properties

QAtomicInt _ref
 

Detailed Description

Definition at line 209 of file qthread_p.h.

Constructors and Destructors

◆ QThreadData()

QThreadData::QThreadData ( int  initialRefCount = 1)

Definition at line 79 of file qthread.cpp.

Referenced by current(), and qt_free_tls().

80  : _ref(initialRefCount), thread(0), threadId(0),
81  quitNow(false), loopLevel(0), eventDispatcher(0), canWait(true), isAdopted(false)
82 {
83  // fprintf(stderr, "QThreadData %p created\n", this);
84 }
bool canWait
Definition: qthread_p.h:267
bool isAdopted
Definition: qthread_p.h:269
int loopLevel
Definition: qthread_p.h:263
bool quitNow
Definition: qthread_p.h:262
QAtomicInt _ref
Definition: qthread_p.h:211
QThread * thread
Definition: qthread_p.h:260
Qt::HANDLE threadId
Definition: qthread_p.h:261
QAbstractEventDispatcher * eventDispatcher
Definition: qthread_p.h:264

◆ ~QThreadData()

QThreadData::~QThreadData ( )

Definition at line 86 of file qthread.cpp.

87 {
88  Q_ASSERT(_ref == 0);
89 
90  // In the odd case that Qt is running on a secondary thread, the main
91  // thread instance will have been dereffed asunder because of the deref in
92  // QThreadData::current() and the deref in the pthread_destroy. To avoid
93  // crashing during QCoreApplicationData's global static cleanup we need to
94  // safeguard the main thread here.. This fix is a bit crude, but it solves
95  // the problem...
99  }
100 
101  QThread *t = thread;
102  thread = 0;
103  delete t;
104 
105  for (int i = 0; i < postEventList.size(); ++i) {
106  const QPostEvent &pe = postEventList.at(i);
107  if (pe.event) {
108  --pe.receiver->d_func()->postedEvents;
109  pe.event->posted = false;
110  delete pe.event;
111  }
112  }
113 
114  // fprintf(stderr, "QThreadData %p destroyed\n", this);
115 }
static QThread * theMainThread
static void clearCurrentThreadData()
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QPostEventList postEventList
Definition: qthread_p.h:266
ushort posted
Definition: qcoreevent.h:319
QEvent * event
Definition: qthread_p.h:78
QObject * receiver
Definition: qthread_p.h:77
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QAtomicInt _ref
Definition: qthread_p.h:211
QThread * thread
Definition: qthread_p.h:260
The QThread class provides a platform-independent way to manage threads.
Definition: qthread.h:59

Functions

◆ canWaitLocked()

bool QThreadData::canWaitLocked ( )
inline

Definition at line 226 of file qthread_p.h.

Referenced by postEventSourcePrepare().

227  {
229  return canWait;
230  }
bool canWait
Definition: qthread_p.h:267
QMutex mutex
Definition: qthread_p.h:109
QPostEventList postEventList
Definition: qthread_p.h:266
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ clearCurrentThreadData()

void QThreadData::clearCurrentThreadData ( )
static

Definition at line 212 of file qthread_unix.cpp.

Referenced by qt_free_tls(), and ~QThreadData().

213 {
215 }
static void clear_thread_data()

◆ current()

QThreadData * QThreadData::current ( )
static

Definition at line 217 of file qthread_unix.cpp.

Referenced by QThread::currentThread(), QCoreApplication::exec(), extract_location(), QThreadStorageData::get(), QCoreApplication::hasPendingEvents(), QAbstractEventDispatcher::instance(), QObject::moveToThread(), QCoreApplication::postEvent(), postEventSourcePrepare(), QThread::priority(), QCoreApplication::processEvents(), qFlagLocation(), qGlobalPostedEventsCount(), QObject::QObject(), qt_free_tls(), QThreadStorageData::QThreadStorageData(), QCoreApplicationPrivate::removePostedEvent(), QCoreApplication::removePostedEvents(), QCoreApplication::sendPostedEvents(), and QThreadStorageData::set().

218 {
220  if (!data) {
221  void *a;
223  QThread *adopted = static_cast<QThread*>(a);
224  Q_ASSERT(adopted);
225  data = QThreadData::get2(adopted);
226  set_thread_data(data);
227  adopted->d_func()->running = true;
228  adopted->d_func()->finished = false;
229  static_cast<QAdoptedThread *>(adopted)->init();
230  } else {
231  data = new QThreadData;
232  QT_TRY {
233  set_thread_data(data);
234  data->thread = new QAdoptedThread(data);
235  } QT_CATCH(...) {
237  data->deref();
238  data = 0;
239  QT_RETHROW;
240  }
241  data->deref();
242  }
243  data->isAdopted = true;
244  data->threadId = (Qt::HANDLE)pthread_self();
247  }
248  return data;
249 }
void finished()
This signal is emitted when the thread has finished executing.
static QThread * theMainThread
long ASN1_INTEGER_get ASN1_INTEGER * a
bool isAdopted
Definition: qthread_p.h:269
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void deref()
Definition: qthread.cpp:125
#define QT_RETHROW
Definition: qglobal.h:1539
static QThreadData * get2(QThread *thread)
Definition: qthread_p.h:219
QThreadData(int initialRefCount=1)
Definition: qthread.cpp:79
static bool activateCallbacks(Callback, void **)
Definition: qglobal.cpp:3653
static bool init
static const char * data(const QByteArray &arr)
void * HANDLE
Definition: qnamespace.h:1671
#define QT_CATCH(A)
Definition: qglobal.h:1537
static void set_thread_data(QThreadData *data)
QThread * thread
Definition: qthread_p.h:260
The QThread class provides a platform-independent way to manage threads.
Definition: qthread.h:59
Qt::HANDLE threadId
Definition: qthread_p.h:261
#define QT_TRY
Definition: qglobal.h:1536
static QThreadData * get_thread_data()
static void clear_thread_data()

◆ deref()

void QThreadData::deref ( )

Definition at line 125 of file qthread.cpp.

Referenced by QInternal::callFunction(), current(), destroy_current_thread_data(), QObject::moveToThread(), QObject::QObject(), qt_adopted_thread_watcher_function(), qt_free_tls(), QCoreApplicationData::~QCoreApplicationData(), QObjectPrivate::~QObjectPrivate(), and QThreadPrivate::~QThreadPrivate().

126 {
127 #ifndef QT_NO_THREAD
128  if (!_ref.deref())
129  delete this;
130 #endif
131 }
bool deref()
Atomically decrements the value of this QAtomicInt.
QAtomicInt _ref
Definition: qthread_p.h:211

◆ get2()

static QThreadData* QThreadData::get2 ( QThread thread)
inlinestatic

Definition at line 219 of file qthread_p.h.

Referenced by QInternal::callFunction(), current(), QAbstractEventDispatcher::instance(), QObject::moveToThread(), qt_adopted_thread_watcher_function(), qt_free_tls(), QtWndProc(), QThreadPrivate::start(), and QCoreApplicationData::~QCoreApplicationData().

220  { Q_ASSERT_X(thread != 0, "QThread", "internal error"); return thread->d_func()->data; }
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837

◆ ref()

void QThreadData::ref ( )

Definition at line 117 of file qthread.cpp.

Referenced by QInternal::callFunction(), QObject::moveToThread(), QObject::QObject(), QObjectPrivate::setThreadData_helper(), and QThreadPrivate::start().

118 {
119 #ifndef QT_NO_THREAD
120  (void) _ref.ref();
121  Q_ASSERT(_ref != 0);
122 #endif
123 }
bool ref()
Atomically increments the value of this QAtomicInt.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QAtomicInt _ref
Definition: qthread_p.h:211

Properties

◆ _ref

QAtomicInt QThreadData::_ref
private

Definition at line 211 of file qthread_p.h.

Referenced by deref(), and ~QThreadData().

◆ canWait

bool QThreadData::canWait

◆ eventDispatcher

QAbstractEventDispatcher* QThreadData::eventDispatcher

◆ eventLoops

QStack<QEventLoop *> QThreadData::eventLoops

◆ flaggedSignatures

FlaggedDebugSignatures QThreadData::flaggedSignatures

Definition at line 275 of file qthread_p.h.

Referenced by qFlagLocation().

◆ isAdopted

bool QThreadData::isAdopted

◆ loopLevel

int QThreadData::loopLevel

◆ postEventList

QPostEventList QThreadData::postEventList

◆ quitNow

bool QThreadData::quitNow

◆ thread

QThread* QThreadData::thread

◆ threadId

Qt::HANDLE QThreadData::threadId

◆ tls

QVector<void *> QThreadData::tls

The documentation for this class was generated from the following files: