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

Public Functions

void post (QWaitConditionEvent *wce, bool ret)
 
QWaitConditionEventpre ()
 
bool wait (unsigned long time)
 
bool wait (QWaitConditionEvent *wce, unsigned long time)
 

Public Variables

pthread_cond_t cond
 
EventQueue freeQueue
 
QMutex mtx
 
pthread_mutex_t mutex
 
EventQueue queue
 
int waiters
 
int wakeups
 

Detailed Description

Definition at line 64 of file qwaitcondition_unix.cpp.

Functions

◆ post()

void QWaitConditionPrivate::post ( QWaitConditionEvent wce,
bool  ret 
)

Definition at line 124 of file qwaitcondition_win.cpp.

125 {
126  mtx.lock();
127 
128  // remove 'wce' from the queue
129  queue.removeAll(wce);
130  ResetEvent(wce->event);
131  freeQueue.append(wce);
132 
133  // wakeups delivered after the timeout should be forwarded to the next waiter
134  if (!ret && wce->wokenUp && !queue.isEmpty()) {
135  QWaitConditionEvent *other = queue.first();
136  SetEvent(other->event);
137  other->wokenUp = true;
138  }
139 
140  mtx.unlock();
141 }
void lock()
Locks the mutex.
Definition: qmutex.cpp:151
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
void unlock()
Unlocks the mutex.
Definition: qmutex.cpp:296
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
Definition: qlist.h:770

◆ pre()

QWaitConditionEvent * QWaitConditionPrivate::pre ( )

Definition at line 89 of file qwaitcondition_win.cpp.

90 {
91  mtx.lock();
92  QWaitConditionEvent *wce =
94  wce->priority = GetThreadPriority(GetCurrentThread());
95  wce->wokenUp = false;
96 
97  // insert 'wce' into the queue (sorted by priority)
98  int index = 0;
99  for (; index < queue.size(); ++index) {
100  QWaitConditionEvent *current = queue.at(index);
101  if (current->priority < wce->priority)
102  break;
103  }
104  queue.insert(index, wce);
105  mtx.unlock();
106 
107  return wce;
108 }
void lock()
Locks the mutex.
Definition: qmutex.cpp:151
void insert(int i, const T &t)
Inserts value at index position i in the list.
Definition: qlist.h:575
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
T takeFirst()
Removes the first item in the list and returns it.
Definition: qlist.h:489
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void unlock()
Unlocks the mutex.
Definition: qmutex.cpp:296
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
quint16 index

◆ wait() [1/2]

bool QWaitConditionPrivate::wait ( unsigned long  time)
inline

Definition at line 71 of file qwaitcondition_unix.cpp.

72  {
73  int code;
74  forever {
75  if (time != ULONG_MAX) {
76  struct timeval tv;
77  gettimeofday(&tv, 0);
78 
79  timespec ti;
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;
83 
84  code = pthread_cond_timedwait(&cond, &mutex, &ti);
85  } else {
86  code = pthread_cond_wait(&cond, &mutex);
87  }
88  if (code == 0 && wakeups == 0) {
89  // many vendors warn of spurios wakeups from
90  // pthread_cond_wait(), especially after signal delivery,
91  // even though POSIX doesn't allow for it... sigh
92  continue;
93  }
94  break;
95  }
96 
97  Q_ASSERT_X(waiters > 0, "QWaitCondition::wait", "internal error (waiters)");
98  --waiters;
99  if (code == 0) {
100  Q_ASSERT_X(wakeups > 0, "QWaitCondition::wait", "internal error (wakeups)");
101  --wakeups;
102  }
103  report_error(pthread_mutex_unlock(&mutex), "QWaitCondition::wait()", "mutex unlock");
104 
105  if (code && code != ETIMEDOUT)
106  report_error(code, "QWaitCondition::wait()", "cv wait");
107 
108  return (code == 0);
109  }
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
static void report_error(int code, const char *where, const char *what)
#define forever
This macro is provided for convenience for writing infinite loops.
Definition: qglobal.h:2452

◆ wait() [2/2]

bool QWaitConditionPrivate::wait ( QWaitConditionEvent wce,
unsigned long  time 
)

Definition at line 110 of file qwaitcondition_win.cpp.

111 {
112  // wait for the event
113  bool ret = false;
114  switch (WaitForSingleObject(wce->event, time)) {
115  default: break;
116 
117  case WAIT_OBJECT_0:
118  ret = true;
119  break;
120  }
121  return ret;
122 }
#define WAIT_OBJECT_0

Properties

◆ cond

pthread_cond_t QWaitConditionPrivate::cond

Definition at line 67 of file qwaitcondition_unix.cpp.

◆ freeQueue

EventQueue QWaitConditionPrivate::freeQueue

Definition at line 82 of file qwaitcondition_win.cpp.

◆ mtx

QMutex QWaitConditionPrivate::mtx

Definition at line 80 of file qwaitcondition_win.cpp.

◆ mutex

pthread_mutex_t QWaitConditionPrivate::mutex

Definition at line 66 of file qwaitcondition_unix.cpp.

Referenced by QMutexLocker::relock(), and QMutexLocker::unlock().

◆ queue

EventQueue QWaitConditionPrivate::queue

Definition at line 81 of file qwaitcondition_win.cpp.

◆ waiters

int QWaitConditionPrivate::waiters

Definition at line 68 of file qwaitcondition_unix.cpp.

Referenced by wait().

◆ wakeups

int QWaitConditionPrivate::wakeups

Definition at line 69 of file qwaitcondition_unix.cpp.

Referenced by wait().


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