Qt 4.8
Public Functions | Properties | List of all members
QWaitCondition Class Reference

#include <qwaitcondition.h>

Public Functions

 QWaitCondition ()
 
bool wait (QMutex *mutex, unsigned long time=ULONG_MAX)
 
bool wait (QReadWriteLock *readWriteLock, unsigned long time=ULONG_MAX)
 
void wakeAll ()
 
void wakeOne ()
 
 ~QWaitCondition ()
 

Properties

QWaitConditionPrivated
 

Detailed Description

Definition at line 61 of file qwaitcondition.h.

Constructors and Destructors

◆ QWaitCondition()

QWaitCondition::QWaitCondition ( )

Definition at line 113 of file qwaitcondition_unix.cpp.

Referenced by QWaitConditionPrivate::post().

114 {
115  d = new QWaitConditionPrivate;
116  report_error(pthread_mutex_init(&d->mutex, NULL), "QWaitCondition", "mutex init");
117  report_error(pthread_cond_init(&d->cond, NULL), "QWaitCondition", "cv init");
118  d->waiters = d->wakeups = 0;
119 }
QWaitConditionPrivate * d
static void report_error(int code, const char *where, const char *what)

◆ ~QWaitCondition()

QWaitCondition::~QWaitCondition ( )

Definition at line 122 of file qwaitcondition_unix.cpp.

Referenced by QWaitConditionPrivate::post().

123 {
124  report_error(pthread_cond_destroy(&d->cond), "QWaitCondition", "cv destroy");
125  report_error(pthread_mutex_destroy(&d->mutex), "QWaitCondition", "mutex destroy");
126  delete d;
127 }
QWaitConditionPrivate * d
static void report_error(int code, const char *where, const char *what)

Functions

◆ wait() [1/2]

bool QWaitCondition::wait ( QMutex mutex,
unsigned long  time = ULONG_MAX 
)

Definition at line 145 of file qwaitcondition_unix.cpp.

Referenced by QFutureInterfaceBasePrivate::internal_waitForNextResult(), QReadWriteLock::lockForRead(), QReadWriteLock::lockForWrite(), QWaitConditionPrivate::post(), QDeclarativeWorkerScriptEngine::QDeclarativeWorkerScriptEngine(), QThreadPoolThread::run(), QWindowsPipeWriter::run(), QFileInfoGatherer::run(), QDnotifySignalThread::startNotify(), QFSEventsFileSystemWatcherEngine::stop(), QDeclarativeListModelWorkerAgent::sync(), QReadWriteLock::tryLockForRead(), QReadWriteLock::tryLockForWrite(), QThreadPoolPrivate::waitForDone(), QFutureInterfaceBase::waitForFinished(), QDBusConnectionPrivate::waitForFinished(), QFutureInterfaceBase::waitForResult(), QFutureInterfaceBase::waitForResume(), QWindowsPipeWriter::waitForWrite(), and QFSEventsFileSystemWatcherEngine::warmUpFSEvents().

146 {
147  if (! mutex)
148  return false;
149  if (mutex->d->recursive) {
150  qWarning("QWaitCondition: cannot wait on recursive mutexes");
151  return false;
152  }
153 
154  report_error(pthread_mutex_lock(&d->mutex), "QWaitCondition::wait()", "mutex lock");
155  ++d->waiters;
156  mutex->unlock();
157 
158  bool returnValue = d->wait(time);
159 
160  mutex->lock();
161 
162  return returnValue;
163 }
QMutexData * d
Definition: qmutex.h:98
void lock()
Locks the mutex.
Definition: qmutex.cpp:151
bool wait(unsigned long time)
QWaitConditionPrivate * d
Q_CORE_EXPORT void qWarning(const char *,...)
const uint recursive
Definition: qmutex.h:159
void unlock()
Unlocks the mutex.
Definition: qmutex.cpp:296
static void report_error(int code, const char *where, const char *what)

◆ wait() [2/2]

bool QWaitCondition::wait ( QReadWriteLock readWriteLock,
unsigned long  time = ULONG_MAX 
)

Definition at line 165 of file qwaitcondition_unix.cpp.

166 {
167  if (!readWriteLock || readWriteLock->d->accessCount == 0)
168  return false;
169  if (readWriteLock->d->accessCount < -1) {
170  qWarning("QWaitCondition: cannot wait on QReadWriteLocks with recursive lockForWrite()");
171  return false;
172  }
173 
174  report_error(pthread_mutex_lock(&d->mutex), "QWaitCondition::wait()", "mutex lock");
175  ++d->waiters;
176 
177  int previousAccessCount = readWriteLock->d->accessCount;
178  readWriteLock->unlock();
179 
180  bool returnValue = d->wait(time);
181 
182  if (previousAccessCount < 0)
183  readWriteLock->lockForWrite();
184  else
185  readWriteLock->lockForRead();
186 
187  return returnValue;
188 }
void unlock()
Unlocks the lock.
void lockForWrite()
Locks the lock for writing.
bool wait(unsigned long time)
QReadWriteLockPrivate * d
QWaitConditionPrivate * d
Q_CORE_EXPORT void qWarning(const char *,...)
void lockForRead()
Locks the lock for reading.
static void report_error(int code, const char *where, const char *what)

◆ wakeAll()

void QWaitCondition::wakeAll ( )

Definition at line 137 of file qwaitcondition_unix.cpp.

Referenced by QFutureInterfaceBase::cancel(), QDnotifySignalThread::event(), QDeclarativeListModelWorkerAgent::event(), QFileInfoGatherer::fetchExtendedInformation(), QThreadPrivate::finish(), QFutureInterfaceBasePrivate::internal_setThrottled(), QWaitConditionPrivate::post(), QThreadPoolThread::registerThreadInactive(), QFutureInterfaceBase::reportException(), QFutureInterfaceBase::reportFinished(), QFutureInterfaceBase::reportResultsReady(), QThreadPoolPrivate::reset(), QFSEventsFileSystemWatcherEngine::run(), QFutureInterfaceBase::setPaused(), QFutureInterfaceBase::setThrottled(), QFutureInterfaceBase::togglePaused(), QReadWriteLock::unlock(), QFSEventsFileSystemWatcherEngine::updateFiles(), and QDBusConnectionPrivate::waitForFinished().

138 {
139  report_error(pthread_mutex_lock(&d->mutex), "QWaitCondition::wakeAll()", "mutex lock");
140  d->wakeups = d->waiters;
141  report_error(pthread_cond_broadcast(&d->cond), "QWaitCondition::wakeAll()", "cv broadcast");
142  report_error(pthread_mutex_unlock(&d->mutex), "QWaitCondition::wakeAll()", "mutex unlock");
143 }
QWaitConditionPrivate * d
static void report_error(int code, const char *where, const char *what)

◆ wakeOne()

void QWaitCondition::wakeOne ( )

Definition at line 129 of file qwaitcondition_unix.cpp.

Referenced by QWaitConditionPrivate::post(), QWindowsPipeWriter::run(), QReadWriteLock::unlock(), QWindowsPipeWriter::write(), QFileInfoGatherer::~QFileInfoGatherer(), and QWindowsPipeWriter::~QWindowsPipeWriter().

130 {
131  report_error(pthread_mutex_lock(&d->mutex), "QWaitCondition::wakeOne()", "mutex lock");
132  d->wakeups = qMin(d->wakeups + 1, d->waiters);
133  report_error(pthread_cond_signal(&d->cond), "QWaitCondition::wakeOne()", "cv signal");
134  report_error(pthread_mutex_unlock(&d->mutex), "QWaitCondition::wakeOne()", "mutex unlock");
135 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
QWaitConditionPrivate * d
static void report_error(int code, const char *where, const char *what)

Properties

◆ d

QWaitConditionPrivate* QWaitCondition::d
private

Definition at line 76 of file qwaitcondition.h.


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