42 #include "qplatformdefs.h" 58 static void report_error(
int code,
const char *where,
const char *what)
71 bool wait(
unsigned long time)
75 if (time != ULONG_MAX) {
80 ti.tv_nsec = (tv.tv_usec + (time % 1000) * 1000) * 1000;
81 ti.tv_sec = tv.tv_sec + (time / 1000) + (ti.tv_nsec / 1000000000);
82 ti.tv_nsec %= 1000000000;
84 code = pthread_cond_timedwait(&cond, &mutex, &ti);
86 code = pthread_cond_wait(&cond, &mutex);
88 if (code == 0 && wakeups == 0) {
97 Q_ASSERT_X(waiters > 0,
"QWaitCondition::wait",
"internal error (waiters)");
100 Q_ASSERT_X(wakeups > 0,
"QWaitCondition::wait",
"internal error (wakeups)");
103 report_error(pthread_mutex_unlock(&mutex),
"QWaitCondition::wait()",
"mutex unlock");
105 if (code && code != ETIMEDOUT)
106 report_error(code,
"QWaitCondition::wait()",
"cv wait");
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;
124 report_error(pthread_cond_destroy(&
d->cond),
"QWaitCondition",
"cv destroy");
125 report_error(pthread_mutex_destroy(&
d->mutex),
"QWaitCondition",
"mutex destroy");
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");
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");
150 qWarning(
"QWaitCondition: cannot wait on recursive mutexes");
154 report_error(pthread_mutex_lock(&
d->mutex),
"QWaitCondition::wait()",
"mutex lock");
158 bool returnValue =
d->wait(time);
167 if (!readWriteLock || readWriteLock->
d->
accessCount == 0)
170 qWarning(
"QWaitCondition: cannot wait on QReadWriteLocks with recursive lockForWrite()");
174 report_error(pthread_mutex_lock(&
d->mutex),
"QWaitCondition::wait()",
"mutex lock");
177 int previousAccessCount = readWriteLock->
d->
accessCount;
180 bool returnValue =
d->wait(time);
182 if (previousAccessCount < 0)
192 #endif // QT_NO_THREAD
QString qt_error_string(int errorCode)
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
#define QT_END_NAMESPACE
This macro expands to.
void lock()
Locks the mutex.
The QMutex class provides access serialization between threads.
void unlock()
Unlocks the lock.
void lockForWrite()
Locks the lock for writing.
bool wait(unsigned long time)
QReadWriteLockPrivate * d
#define QT_BEGIN_NAMESPACE
This macro expands to.
Q_CORE_EXPORT void qWarning(const char *,...)
void lockForRead()
Locks the lock for reading.
void unlock()
Unlocks the mutex.
bool wait(QMutex *mutex, unsigned long time=ULONG_MAX)
#define Q_ASSERT_X(cond, where, what)
The QReadWriteLock class provides read-write locking.
static void report_error(int code, const char *where, const char *what)
#define qPrintable(string)
#define forever
This macro is provided for convenience for writing infinite loops.