Qt 4.8
Public Functions | Static Public Functions | Properties | List of all members
QOrderedMutexLocker Class Reference

#include <qorderedmutexlocker_p.h>

Public Functions

 QOrderedMutexLocker (QMutex *m1, QMutex *m2)
 
void relock ()
 
void unlock ()
 
 ~QOrderedMutexLocker ()
 

Static Public Functions

static bool relock (QMutex *mtx1, QMutex *mtx2)
 

Properties

bool locked
 
QMutexmtx1
 
QMutexmtx2
 

Detailed Description

Definition at line 64 of file qorderedmutexlocker_p.h.

Constructors and Destructors

◆ QOrderedMutexLocker()

QOrderedMutexLocker::QOrderedMutexLocker ( QMutex m1,
QMutex m2 
)
inline

Definition at line 67 of file qorderedmutexlocker_p.h.

68  : mtx1((m1 == m2) ? m1 : (m1 < m2 ? m1 : m2)),
69  mtx2((m1 == m2) ? 0 : (m1 < m2 ? m2 : m1)),
70  locked(false)
71  {
72  relock();
73  }

◆ ~QOrderedMutexLocker()

QOrderedMutexLocker::~QOrderedMutexLocker ( )
inline

Definition at line 74 of file qorderedmutexlocker_p.h.

75  {
76  unlock();
77  }

Functions

◆ relock() [1/2]

void QOrderedMutexLocker::relock ( )
inline

Definition at line 79 of file qorderedmutexlocker_p.h.

Referenced by QMetaObjectPrivate::disconnectHelper(), QOrderedMutexLocker(), and QObject::~QObject().

80  {
81  if (!locked) {
82  if (mtx1) mtx1->lockInline();
83  if (mtx2) mtx2->lockInline();
84  locked = true;
85  }
86  }
void lockInline()
Definition: qmutex.h:198

◆ relock() [2/2]

static bool QOrderedMutexLocker::relock ( QMutex mtx1,
QMutex mtx2 
)
inlinestatic

Definition at line 97 of file qorderedmutexlocker_p.h.

98  {
99  // mtx1 is already locked, mtx2 not... do we need to unlock and relock?
100  if (mtx1 == mtx2)
101  return false;
102  if (mtx1 < mtx2) {
103  mtx2->lockInline();
104  return true;
105  }
106  if (!mtx2->tryLockInline()) {
107  mtx1->unlock();
108  mtx2->lock();
109  mtx1->lock();
110  }
111  return true;
112  }
void lock()
Locks the mutex.
Definition: qmutex.cpp:151
void lockInline()
Definition: qmutex.h:198
void unlock()
Unlocks the mutex.
Definition: qmutex.cpp:296
bool tryLockInline()
Definition: qmutex.h:197

◆ unlock()

void QOrderedMutexLocker::unlock ( )
inline

Definition at line 88 of file qorderedmutexlocker_p.h.

Referenced by QObject::moveToThread(), and ~QOrderedMutexLocker().

89  {
90  if (locked) {
91  if (mtx1) mtx1->unlockInline();
92  if (mtx2) mtx2->unlockInline();
93  locked = false;
94  }
95  }
void unlockInline()
Definition: qmutex.h:196

Properties

◆ locked

bool QOrderedMutexLocker::locked
private

Definition at line 116 of file qorderedmutexlocker_p.h.

Referenced by relock(), and unlock().

◆ mtx1

QMutex* QOrderedMutexLocker::mtx1
private

Definition at line 115 of file qorderedmutexlocker_p.h.

Referenced by relock(), and unlock().

◆ mtx2

QMutex * QOrderedMutexLocker::mtx2
private

Definition at line 115 of file qorderedmutexlocker_p.h.

Referenced by relock(), and unlock().


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