Public Member Functions | Private Member Functions | Private Attributes | List of all members
QWaitCondition Class Reference

#include <qwaitcondition.h>

Public Member Functions

 QWaitCondition ()
 
 ~QWaitCondition ()
 
void wait (QMutex *mutex)
 
void wakeOne ()
 
void wakeAll ()
 

Private Member Functions

 QWaitCondition (const QWaitCondition &)
 
QWaitConditionoperator= (const QWaitCondition &)
 

Private Attributes

QWaitConditionPrivated
 

Detailed Description

Definition at line 50 of file qwaitcondition.h.

Constructor & Destructor Documentation

QWaitCondition::QWaitCondition ( )

Definition at line 92 of file qwaitcondition_unix.cpp.

93 {
95  report_error(pthread_mutex_init(&d->mutex, NULL), "QWaitCondition", "mutex init");
96  report_error(pthread_cond_init(&d->cond, NULL), "QWaitCondition", "cv init");
97  d->waiters = d->wakeups = 0;
98 }
QWaitConditionPrivate * d
static void report_error(int code, const char *where, const char *what)
QWaitCondition::~QWaitCondition ( )

Definition at line 101 of file qwaitcondition_unix.cpp.

102 {
103  report_error(pthread_cond_destroy(&d->cond), "QWaitCondition", "cv destroy");
104  report_error(pthread_mutex_destroy(&d->mutex), "QWaitCondition", "mutex destroy");
105  delete d;
106 }
QWaitConditionPrivate * d
static void report_error(int code, const char *where, const char *what)
QWaitCondition::QWaitCondition ( const QWaitCondition )
private

Member Function Documentation

QWaitCondition& QWaitCondition::operator= ( const QWaitCondition )
private
void QWaitCondition::wait ( QMutex mutex)

Definition at line 124 of file qwaitcondition_unix.cpp.

125 {
126  if (!mutex) return;
127 
128  report_error(pthread_mutex_lock(&d->mutex), "QWaitCondition::wait()", "mutex lock");
129  ++d->waiters;
130  mutex->unlock();
131  d->wait();
132  mutex->lock();
133 }
void lock()
Definition: qmutex.cpp:58
QWaitConditionPrivate * d
void unlock()
Definition: qmutex.cpp:85
static void report_error(int code, const char *where, const char *what)
void QWaitCondition::wakeAll ( )

Definition at line 116 of file qwaitcondition_unix.cpp.

117 {
118  report_error(pthread_mutex_lock(&d->mutex), "QWaitCondition::wakeAll()", "mutex lock");
119  d->wakeups = d->waiters;
120  report_error(pthread_cond_broadcast(&d->cond), "QWaitCondition::wakeAll()", "cv broadcast");
121  report_error(pthread_mutex_unlock(&d->mutex), "QWaitCondition::wakeAll()", "mutex unlock");
122 }
QWaitConditionPrivate * d
static void report_error(int code, const char *where, const char *what)
void QWaitCondition::wakeOne ( )

Definition at line 108 of file qwaitcondition_unix.cpp.

109 {
110  report_error(pthread_mutex_lock(&d->mutex), "QWaitCondition::wakeOne()", "mutex lock");
111  d->wakeups = MIN(d->wakeups + 1, d->waiters);
112  report_error(pthread_cond_signal(&d->cond), "QWaitCondition::wakeOne()", "cv signal");
113  report_error(pthread_mutex_unlock(&d->mutex), "QWaitCondition::wakeOne()", "mutex unlock");
114 }
QWaitConditionPrivate * d
#define MIN(a, b)
static void report_error(int code, const char *where, const char *what)

Member Data Documentation

QWaitConditionPrivate* QWaitCondition::d
private

Definition at line 65 of file qwaitcondition.h.


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