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

#include <qmutex.h>

Public Member Functions

 QMutex ()
 
 ~QMutex ()
 
void lock ()
 
bool tryLock ()
 
void unlock ()
 

Private Member Functions

 QMutex (const QMutex &)
 
QMutexoperator= (const QMutex &)
 

Private Attributes

QMutexPrivated
 

Detailed Description

Definition at line 49 of file qmutex.h.

Constructor & Destructor Documentation

QMutex::QMutex ( )

Definition at line 49 of file qmutex.cpp.

49  : d(new QMutexPrivate())
50 {
51 }
QMutexPrivate * d
Definition: qmutex.h:63
QMutex::~QMutex ( )

Definition at line 53 of file qmutex.cpp.

54 {
55  delete d;
56 }
QMutexPrivate * d
Definition: qmutex.h:63
QMutex::QMutex ( const QMutex )
private

Member Function Documentation

void QMutex::lock ( )

Definition at line 58 of file qmutex.cpp.

59 {
60  //printf("%p: QMutex::lock(): enter\n",this);
61  bool isLocked;
62  isLocked = d->contenders.testAndSet(0, 1);
63  if (!isLocked)
64  {
65  isLocked = d->contenders.fetchAndAdd(1)==0;
66  if (!isLocked)
67  {
68  // didn't get the lock, wait for it
69  //printf("%p: QMutex::lock(): wait() %d\n",this,(int)d->contenders);
70  d->wait();
71 
72  // release lock
74  }
75  }
76  //printf("%p: QMutex::lock(): leave\n",this);
77 }
QAtomicInt contenders
Definition: qmutex_p.h:77
int fetchAndAdd(int valueToAdd)
bool testAndSet(int expectedValue, int newValue)
Definition: qmutex_unix.cpp:95
QMutexPrivate * d
Definition: qmutex.h:63
QMutex& QMutex::operator= ( const QMutex )
private
bool QMutex::tryLock ( )

Definition at line 79 of file qmutex.cpp.

80 {
81  bool isLocked = d->contenders.testAndSet(0, 1);
82  return isLocked;
83 }
QAtomicInt contenders
Definition: qmutex_p.h:77
bool testAndSet(int expectedValue, int newValue)
Definition: qmutex_unix.cpp:95
QMutexPrivate * d
Definition: qmutex.h:63
void QMutex::unlock ( )

Definition at line 85 of file qmutex.cpp.

86 {
87  //printf("%p: QMutex::unlock(): enter %d\n",this,(int)d->contenders);
88  if (!d->contenders.testAndSet(1, 0))
89  {
90  //printf("%p: QMutex::unlock(): wakeUp()\n",this);
91  d->wakeUp();
92  }
93  //printf("%p: QMutex::unlock(): leave\n",this);
94 }
QAtomicInt contenders
Definition: qmutex_p.h:77
bool testAndSet(int expectedValue, int newValue)
Definition: qmutex_unix.cpp:95
QMutexPrivate * d
Definition: qmutex.h:63

Member Data Documentation

QMutexPrivate* QMutex::d
private

Definition at line 63 of file qmutex.h.


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