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

#include <qmutex_p.h>

Inheritance diagram for QMutexPrivate:
QMutexData

Public Types

enum  { MaximumSpinTimeThreshold = 1000000 }
 

Public Functions

 QMutexPrivate (QMutex::RecursionMode mode)
 
bool wait (int timeout=-1)
 
void wakeUp ()
 
 ~QMutexPrivate ()
 

Public Variables

volatile qint64 averageWaitTime
 
uint count
 
HANDLE event
 
volatile qint64 maximumSpinTime
 
Qt::HANDLE owner
 
- Public Variables inherited from QMutexData
QAtomicInt contenders
 
const uint recursive: 1
 
uint reserved: 31
 

Additional Inherited Members

- Protected Functions inherited from QMutexData
 QMutexData (QMutex::RecursionMode mode)
 
 ~QMutexData ()
 

Detailed Description

Definition at line 67 of file qmutex_p.h.

Enumerations

◆ anonymous enum

anonymous enum
Enumerator
MaximumSpinTimeThreshold 

Definition at line 76 of file qmutex_p.h.

Constructors and Destructors

◆ QMutexPrivate()

QMutexPrivate::QMutexPrivate ( QMutex::RecursionMode  mode)

Definition at line 77 of file qmutex_unix.cpp.

79 {
80 #if !defined(Q_OS_LINUX) || defined(QT_LINUXBASE)
81  wakeup = false;
82  report_error(pthread_mutex_init(&mutex, NULL), "QMutex", "mutex init");
83  report_error(pthread_cond_init(&cond, NULL), "QMutex", "cv init");
84 #endif
85 }
QMutexData(QMutex::RecursionMode mode)
Definition: qmutex_p.h:93
volatile qint64 maximumSpinTime
Definition: qmutex_p.h:77
volatile qint64 averageWaitTime
Definition: qmutex_p.h:78
static void report_error(int code, const char *where, const char *what)
uint count
Definition: qmutex_p.h:80
Qt::HANDLE owner
Definition: qmutex_p.h:79

◆ ~QMutexPrivate()

QMutexPrivate::~QMutexPrivate ( )

Definition at line 87 of file qmutex_unix.cpp.

88 {
89 #if !defined(Q_OS_LINUX) || defined(QT_LINUXBASE)
90  report_error(pthread_cond_destroy(&cond), "QMutex", "cv destroy");
91  report_error(pthread_mutex_destroy(&mutex), "QMutex", "mutex destroy");
92 #endif
93 }
static void report_error(int code, const char *where, const char *what)

Functions

◆ wait()

bool QMutexPrivate::wait ( int  timeout = -1)

Definition at line 102 of file qmutex_unix.cpp.

Referenced by QMutex::lock(), QMutex::lockInternal(), and QMutex::tryLock().

103 {
104  struct timespec ts, *pts = 0;
106  if (timeout >= 0) {
107  ts.tv_nsec = ((timeout % 1000) * 1000) * 1000;
108  ts.tv_sec = (timeout / 1000);
109  pts = &ts;
110  timer.start();
111  }
112  while (contenders.fetchAndStoreAcquire(2) > 0) {
113  int r = _q_futex(&contenders._q_value, FUTEX_WAIT, 2, pts, 0, 0);
114  if (r != 0 && errno == ETIMEDOUT)
115  return false;
116 
117  if (pts) {
118  // recalculate the timeout
119  qint64 xtimeout = timeout * 1000 * 1000;
120  xtimeout -= timer.nsecsElapsed();
121  if (xtimeout < 0) {
122  // timer expired after we returned
123  return false;
124  }
125 
126  ts.tv_sec = xtimeout / Q_INT64_C(1000) / 1000 / 1000;
127  ts.tv_nsec = xtimeout % (Q_INT64_C(1000) * 1000 * 1000);
128  }
129  }
130  return true;
131 }
QAtomicInt contenders
Definition: qmutex.h:158
volatile int _q_value
Definition: qbasicatomic.h:64
EventLoopTimerRef timer
The QElapsedTimer class provides a fast way to calculate elapsed times.
Definition: qelapsedtimer.h:53
static int _q_futex(volatile int *addr, int op, int val, const struct timespec *timeout, int *addr2, int val2)
Definition: qmutex_unix.cpp:97
qint64 nsecsElapsed() const
Returns the number of nanoseconds since this QElapsedTimer was last started.
__int64 qint64
Definition: qglobal.h:942
#define Q_INT64_C(c)
Definition: qglobal.h:940
int fetchAndStoreAcquire(int newValue)
Atomic fetch-and-store.
void start()
Starts this timer.
int errno

◆ wakeUp()

void QMutexPrivate::wakeUp ( )

Definition at line 133 of file qmutex_unix.cpp.

Referenced by QMutex::unlock().

134 {
136  (void) _q_futex(&contenders._q_value, FUTEX_WAKE, 1, 0, 0, 0);
137 }
QAtomicInt contenders
Definition: qmutex.h:158
volatile int _q_value
Definition: qbasicatomic.h:64
static int _q_futex(volatile int *addr, int op, int val, const struct timespec *timeout, int *addr2, int val2)
Definition: qmutex_unix.cpp:97
int fetchAndStoreRelease(int newValue)
Atomic fetch-and-store.

Properties

◆ averageWaitTime

volatile qint64 QMutexPrivate::averageWaitTime

Definition at line 78 of file qmutex_p.h.

Referenced by QMutex::lockInternal().

◆ count

uint QMutexPrivate::count

Definition at line 80 of file qmutex_p.h.

Referenced by QMutex::lock(), QMutex::tryLock(), and QMutex::unlock().

◆ event

HANDLE QMutexPrivate::event

Definition at line 87 of file qmutex_p.h.

◆ maximumSpinTime

volatile qint64 QMutexPrivate::maximumSpinTime

Definition at line 77 of file qmutex_p.h.

Referenced by QMutex::lockInternal().

◆ owner

Qt::HANDLE QMutexPrivate::owner

Definition at line 79 of file qmutex_p.h.

Referenced by QMutex::lock(), QMutex::tryLock(), and QMutex::unlock().


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