Qt 4.8
Public Functions | Static Public Functions | Public Variables | List of all members
QThreadPrivate Class Reference

#include <qthread_p.h>

Inheritance diagram for QThreadPrivate:
QObjectPrivate QObjectData

Public Functions

 QThreadPrivate (QThreadData *d=0)
 
 ~QThreadPrivate ()
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Static Public Functions

static void createEventDispatcher (QThreadData *data)
 
static void finish (void *)
 
static void finish (void *, bool lockAnyway=true)
 
static void * start (void *arg)
 
static unsigned int __stdcall start (void *)
 
static QThreadthreadForId (int id)
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 

Public Variables

QThreadDatadata
 
bool exited
 
bool finished
 
HANDLE handle
 
unsigned int id
 
bool isInFinish
 
QMutex mutex
 
QThread::Priority priority
 
int returnCode
 
bool running
 
uint stackSize
 
bool terminated
 
bool terminatePending
 
bool terminationEnabled
 
QWaitCondition thread_done
 
pthread_t thread_id
 
int waiters
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 

Additional Inherited Members

- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 

Detailed Description

Definition at line 137 of file qthread_p.h.

Constructors and Destructors

◆ QThreadPrivate()

QThreadPrivate::QThreadPrivate ( QThreadData d = 0)

Definition at line 173 of file qthread.cpp.

174  : QObjectPrivate(), running(false), finished(false), terminated(false),
175  isInFinish(false), exited(false), returnCode(-1),
177 {
178 #if defined (Q_OS_UNIX)
179  thread_id = 0;
180 #elif defined (Q_WS_WIN)
181  handle = 0;
182  id = 0;
183  waiters = 0;
184 #endif
185 #if defined (Q_WS_WIN) || defined (Q_OS_SYMBIAN)
186  terminationEnabled = true;
187  terminatePending = false;
188 #endif
189 
190  if (!data)
191  data = new QThreadData;
192 }
pthread_t thread_id
Definition: qthread_p.h:161
QObjectPrivate(int version=QObjectPrivateVersion)
Definition: qobject.cpp:133
bool terminatePending
Definition: qthread_p.h:183
QThreadData * data
Definition: qthread_p.h:185
QThread::Priority priority
Definition: qthread_p.h:156
bool terminationEnabled
Definition: qthread_p.h:183
HANDLE handle
Definition: qthread_p.h:174

◆ ~QThreadPrivate()

QThreadPrivate::~QThreadPrivate ( )

Definition at line 194 of file qthread.cpp.

195 {
196  data->deref();
197 }
void deref()
Definition: qthread.cpp:125
QThreadData * data
Definition: qthread_p.h:185

Functions

◆ createEventDispatcher()

void QThreadPrivate::createEventDispatcher ( QThreadData data)
static

Definition at line 274 of file qthread_unix.cpp.

Referenced by QEventLoop::QEventLoop(), and qt_adopted_thread_watcher_function().

275 {
276 #if defined(Q_OS_BLACKBERRY)
278 #else
279 #if !defined(QT_NO_GLIB)
280  if (qgetenv("QT_NO_GLIB").isEmpty()
281  && qgetenv("QT_NO_THREADED_GLIB").isEmpty()
284  else
285 #endif
287 #endif
288 
289  data->eventDispatcher->startingUp();
290 }
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
static bool isEmpty(const char *str)
QAbstractEventDispatcher * eventDispatcher
Definition: qthread_p.h:264

◆ finish() [1/2]

void QThreadPrivate::finish ( void *  arg)
static

Definition at line 356 of file qthread_unix.cpp.

Referenced by destroy_current_thread_data(), finish(), qt_adopted_thread_watcher_function(), and start().

357 {
358  QThread *thr = reinterpret_cast<QThread *>(arg);
359  QThreadPrivate *d = thr->d_func();
360 
361  QMutexLocker locker(&d->mutex);
362 
363  d->isInFinish = true;
365  bool terminated = d->terminated;
366  void *data = &d->data->tls;
367  locker.unlock();
368  if (terminated)
369  emit thr->terminated();
370  emit thr->finished();
372  QThreadStorageData::finish((void **)data);
373  locker.relock();
374  d->terminated = false;
375 
376  QAbstractEventDispatcher *eventDispatcher = d->data->eventDispatcher;
377  if (eventDispatcher) {
378  d->data->eventDispatcher = 0;
379  locker.unlock();
380  eventDispatcher->closingDown();
381  delete eventDispatcher;
382  locker.relock();
383  }
384 
385  d->thread_id = 0;
386  d->running = false;
387  d->finished = true;
388 
389  d->isInFinish = false;
390  d->thread_done.wakeAll();
391 }
double d
Definition: qnumeric_p.h:62
static void finish(void **)
pthread_t thread_id
Definition: qthread_p.h:161
void finished()
This signal is emitted when the thread has finished executing.
QVector< void * > tls
Definition: qthread_p.h:268
#define emit
Definition: qobjectdefs.h:76
static void sendPostedEvents()
QThreadData * data
Definition: qthread_p.h:185
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
void terminated()
This signal is emitted when the thread is terminated.
QWaitCondition thread_done
Definition: qthread_p.h:162
QMutex mutex
Definition: qthread_p.h:145
QThread::Priority priority
Definition: qthread_p.h:156
The QThread class provides a platform-independent way to manage threads.
Definition: qthread.h:59
QAbstractEventDispatcher * eventDispatcher
Definition: qthread_p.h:264
The QAbstractEventDispatcher class provides an interface to manage Qt&#39;s event queue.

◆ finish() [2/2]

void QThreadPrivate::finish ( void *  arg,
bool  lockAnyway = true 
)
static

Definition at line 367 of file qthread_win.cpp.

368 {
369  QThread *thr = reinterpret_cast<QThread *>(arg);
370  QThreadPrivate *d = thr->d_func();
371 
372  QMutexLocker locker(lockAnyway ? &d->mutex : 0);
373  d->isInFinish = true;
375  bool terminated = d->terminated;
376  void **tls_data = reinterpret_cast<void **>(&d->data->tls);
377  locker.unlock();
378  if (terminated)
379  emit thr->terminated();
380  emit thr->finished();
382  QThreadStorageData::finish(tls_data);
383  locker.relock();
384 
385  d->terminated = false;
386 
387  QAbstractEventDispatcher *eventDispatcher = d->data->eventDispatcher;
388  if (eventDispatcher) {
389  d->data->eventDispatcher = 0;
390  locker.unlock();
391  eventDispatcher->closingDown();
392  delete eventDispatcher;
393  locker.relock();
394  }
395 
396  d->running = false;
397  d->finished = true;
398  d->isInFinish = false;
399 
400  if (!d->waiters) {
401  CloseHandle(d->handle);
402  d->handle = 0;
403  }
404 
405  d->id = 0;
406 
407 }
double d
Definition: qnumeric_p.h:62
static void finish(void **)
void finished()
This signal is emitted when the thread has finished executing.
QVector< void * > tls
Definition: qthread_p.h:268
unsigned int id
Definition: qthread_p.h:175
#define emit
Definition: qobjectdefs.h:76
static void sendPostedEvents()
QThreadData * data
Definition: qthread_p.h:185
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
void terminated()
This signal is emitted when the thread is terminated.
QMutex mutex
Definition: qthread_p.h:145
QThread::Priority priority
Definition: qthread_p.h:156
The QThread class provides a platform-independent way to manage threads.
Definition: qthread.h:59
QAbstractEventDispatcher * eventDispatcher
Definition: qthread_p.h:264
The QAbstractEventDispatcher class provides an interface to manage Qt&#39;s event queue.
HANDLE handle
Definition: qthread_p.h:174

◆ start() [1/2]

unsigned int __stdcall QT_ENSURE_STACK_ALIGNED_FOR_SSE QThreadPrivate::start ( void *  arg)
static

Definition at line 310 of file qthread_unix.cpp.

Referenced by finish(), qt_adopted_thread_watcher_function(), and QThread::start().

311 {
312  pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
314 
315  QThread *thr = reinterpret_cast<QThread *>(arg);
317 
318  // do we need to reset the thread priority?
319  if (int(thr->d_func()->priority) & ThreadPriorityResetFlag) {
321  }
322 
323  data->threadId = (Qt::HANDLE)pthread_self();
324  set_thread_data(data);
325 
326  data->ref();
327  {
328  QMutexLocker locker(&thr->d_func()->mutex);
329  data->quitNow = thr->d_func()->exited;
330  }
331 
332  // ### TODO: allow the user to create a custom event dispatcher
333  createEventDispatcher(data);
334 
335 #if (defined(Q_OS_LINUX) || (defined(Q_OS_MAC) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6) || defined(Q_OS_QNX))
336  // sets the name of the current thread.
337  QString objectName = thr->objectName();
338 
339  if (Q_LIKELY(objectName.isEmpty()))
340  setCurrentThreadName(thr->d_func()->thread_id, thr->metaObject()->className());
341  else
342  setCurrentThreadName(thr->d_func()->thread_id, objectName.toLocal8Bit());
343 
344 #endif
345 
346  emit thr->started();
347  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
349  thr->run();
350 
352 
353  return 0;
354 }
virtual void run()
The starting point for the thread.
Definition: qthread.cpp:628
void pthread_cleanup_pop(int)
The QString class provides a Unicode character string.
Definition: qstring.h:83
void started()
This signal is emitted when the thread starts executing.
Priority
This enum type indicates how the operating system should schedule newly created threads.
Definition: qthread.h:70
static void setCurrentThreadName(pthread_t threadId, const char *name)
Priority priority() const
Returns the priority for a running thread.
Definition: qthread.cpp:718
static QThreadData * get2(QThread *thread)
Definition: qthread_p.h:219
int pthread_setcancelstate(int, int *)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void pthread_testcancel(void)
#define emit
Definition: qobjectdefs.h:76
void * HANDLE
Definition: qnamespace.h:1671
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
bool quitNow
Definition: qthread_p.h:262
QString objectName
Definition: qobject_p.h:193
QThreadData * data
Definition: qthread_p.h:185
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
void ref()
Definition: qthread.cpp:117
void pthread_cleanup_push(void(*)(void *), void *)
static void set_thread_data(QThreadData *data)
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
QString objectName() const
#define Q_LIKELY(x)
Hints to the compiler that the enclosed condition, expr, is likely to evaluate to true...
Definition: qglobal.h:820
static void finish(void *)
static void createEventDispatcher(QThreadData *data)
The QThread class provides a platform-independent way to manage threads.
Definition: qthread.h:59
Qt::HANDLE threadId
Definition: qthread_p.h:261
void setPriority(Priority priority)
This function sets the priority for a running thread.
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

◆ start() [2/2]

static unsigned int __stdcall QThreadPrivate::start ( void *  )
static

◆ threadForId()

static QThread* QThreadPrivate::threadForId ( int  id)
static

Properties

◆ data

QThreadData* QThreadPrivate::data

Definition at line 185 of file qthread_p.h.

Referenced by QThread::currentThread(), finish(), QThreadPrivate(), and ~QThreadPrivate().

◆ exited

bool QThreadPrivate::exited

Definition at line 152 of file qthread_p.h.

◆ finished

bool QThreadPrivate::finished

◆ handle

HANDLE QThreadPrivate::handle

Definition at line 174 of file qthread_p.h.

Referenced by finish(), and QThreadPrivate().

◆ id

unsigned int QThreadPrivate::id

Definition at line 175 of file qthread_p.h.

Referenced by finish().

◆ isInFinish

bool QThreadPrivate::isInFinish

Definition at line 150 of file qthread_p.h.

Referenced by finish().

◆ mutex

QMutex QThreadPrivate::mutex
mutable

Definition at line 145 of file qthread_p.h.

Referenced by finish().

◆ priority

QThread::Priority QThreadPrivate::priority

Definition at line 156 of file qthread_p.h.

Referenced by finish().

◆ returnCode

int QThreadPrivate::returnCode

Definition at line 153 of file qthread_p.h.

◆ running

bool QThreadPrivate::running

Definition at line 147 of file qthread_p.h.

Referenced by finish().

◆ stackSize

uint QThreadPrivate::stackSize

Definition at line 155 of file qthread_p.h.

◆ terminated

bool QThreadPrivate::terminated

Definition at line 149 of file qthread_p.h.

Referenced by finish().

◆ terminatePending

bool QThreadPrivate::terminatePending

Definition at line 183 of file qthread_p.h.

Referenced by finish(), and QThreadPrivate().

◆ terminationEnabled

bool QThreadPrivate::terminationEnabled

Definition at line 183 of file qthread_p.h.

Referenced by finish(), and QThreadPrivate().

◆ thread_done

QWaitCondition QThreadPrivate::thread_done

Definition at line 162 of file qthread_p.h.

Referenced by finish().

◆ thread_id

pthread_t QThreadPrivate::thread_id

Definition at line 161 of file qthread_p.h.

Referenced by finish(), and QThreadPrivate().

◆ waiters

int QThreadPrivate::waiters

Definition at line 176 of file qthread_p.h.

Referenced by finish(), and QThreadPrivate().


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