Public Member Functions | Public Attributes | List of all members
QWaitConditionPrivate Class Reference

Public Member Functions

void wait ()
 
QWaitConditionEventpre ()
 
void wait (QWaitConditionEvent *wce)
 
void post (QWaitConditionEvent *wce)
 

Public Attributes

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

Detailed Description

Definition at line 54 of file qwaitcondition_unix.cpp.

Member Function Documentation

void QWaitConditionPrivate::post ( QWaitConditionEvent wce)

Definition at line 110 of file qwaitcondition_win32.cpp.

111 {
112  mtx.lock();
113 
114  // remove 'wce' from the queue
115  int idx = queue.find(wce);
116  ASSERT(idx!=-1);
117  queue.take(idx);
118  ResetEvent(wce->event);
119  freeQueue.append(wce);
120 
121  // wakeups delivered after the timeout should be forwarded to the next waiter
122  if (wce->wokenUp && !queue.isEmpty())
123  {
125  SetEvent(other->event);
126  other->wokenUp = TRUE;
127  }
128 
129  mtx.unlock();
130 }
type * getFirst() const
Definition: qinternallist.h:85
void lock()
Definition: qmutex.cpp:58
int find(const type *d)
Definition: qinternallist.h:74
type * take(uint i)
Definition: qinternallist.h:69
void append(const type *d)
Definition: qinternallist.h:61
void unlock()
Definition: qmutex.cpp:85
bool isEmpty() const
Definition: qinternallist.h:57
const bool TRUE
Definition: qglobal.h:371
#define ASSERT(x)
Definition: qglobal.h:590
QWaitConditionEvent * QWaitConditionPrivate::pre ( )

Definition at line 83 of file qwaitcondition_win32.cpp.

84 {
85  mtx.lock();
86  QWaitConditionEvent *wce =
88  wce->priority = GetThreadPriority(GetCurrentThread());
89  wce->wokenUp = FALSE;
90 
91  // insert 'wce' into the queue (sorted by priority)
92  uint index = 0;
93  for (; index < queue.count(); ++index)
94  {
96  if (current->priority < wce->priority)
97  break;
98  }
99  queue.insert(index, wce);
100  mtx.unlock();
101 
102  return wce;
103 }
void lock()
Definition: qmutex.cpp:58
const bool FALSE
Definition: qglobal.h:370
type * take(uint i)
Definition: qinternallist.h:69
bool insert(uint i, const type *d)
Definition: qinternallist.h:58
static Entry * current
void unlock()
Definition: qmutex.cpp:85
bool isEmpty() const
Definition: qinternallist.h:57
type * at(uint i)
Definition: qinternallist.h:81
uint count() const
Definition: qinternallist.h:56
unsigned uint
Definition: qglobal.h:351
void QWaitConditionPrivate::wait ( )
inline

Definition at line 62 of file qwaitcondition_unix.cpp.

63  {
64  int code;
65  for (;;)
66  {
67  code = pthread_cond_wait(&cond, &mutex);
68  if (code == 0 && wakeups == 0)
69  {
70  // many vendors warn of spurios wakeups from
71  // pthread_cond_wait(), especially after signal delivery,
72  // even though POSIX doesn't allow for it... sigh
73  continue;
74  }
75  break;
76  }
77 
78  --waiters;
79  if (code == 0)
80  {
81  --wakeups;
82  }
83  else
84  {
85  report_error(code, "QWaitCondition::wait()", "cv wait");
86  }
87  report_error(pthread_mutex_unlock(&mutex), "QWaitCondition::wait()", "mutex unlock");
88  }
CodeOutputInterface * code
static void report_error(int code, const char *where, const char *what)
void QWaitConditionPrivate::wait ( QWaitConditionEvent wce)

Definition at line 105 of file qwaitcondition_win32.cpp.

106 {
107  WaitForSingleObject(wce->event, INFINITE);
108 }

Member Data Documentation

pthread_cond_t QWaitConditionPrivate::cond

Definition at line 58 of file qwaitcondition_unix.cpp.

EventQueue QWaitConditionPrivate::freeQueue

Definition at line 76 of file qwaitcondition_win32.cpp.

QMutex QWaitConditionPrivate::mtx

Definition at line 74 of file qwaitcondition_win32.cpp.

pthread_mutex_t QWaitConditionPrivate::mutex

Definition at line 57 of file qwaitcondition_unix.cpp.

EventQueue QWaitConditionPrivate::queue

Definition at line 75 of file qwaitcondition_win32.cpp.

int QWaitConditionPrivate::waiters

Definition at line 59 of file qwaitcondition_unix.cpp.

int QWaitConditionPrivate::wakeups

Definition at line 60 of file qwaitcondition_unix.cpp.


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