Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tbb::scoped_lock Class Reference

The scoped locking pattern. More...

#include <mutex.h>

Inheritance diagram for tbb::scoped_lock:
Collaboration diagram for tbb::scoped_lock:

Public Member Functions

 scoped_lock ()
 Construct lock that has not acquired a mutex. More...
 
 scoped_lock (mutex &mutex)
 Acquire lock on given mutex. More...
 
 ~scoped_lock ()
 Release lock (if lock is held). More...
 
void acquire (mutex &mutex)
 Acquire lock on given mutex. More...
 
bool try_acquire (mutex &mutex)
 Try acquire lock on given mutex. More...
 
void release ()
 Release lock. More...
 
 scoped_lock ()
 Construct lock that has not acquired a recursive_mutex. More...
 
 scoped_lock (recursive_mutex &mutex)
 Acquire lock on given mutex. More...
 
 ~scoped_lock ()
 Release lock (if lock is held). More...
 
void acquire (recursive_mutex &mutex)
 Acquire lock on given mutex. More...
 
bool try_acquire (recursive_mutex &mutex)
 Try acquire lock on given recursive_mutex. More...
 
void release ()
 Release lock. More...
 

Private Member Functions

void __TBB_EXPORTED_METHOD internal_acquire (mutex &m)
 All checks from acquire using mutex.state were moved here. More...
 
bool __TBB_EXPORTED_METHOD internal_try_acquire (mutex &m)
 All checks from try_acquire using mutex.state were moved here. More...
 
void __TBB_EXPORTED_METHOD internal_release ()
 All checks from release using mutex.state were moved here. More...
 
void __TBB_EXPORTED_METHOD internal_acquire (recursive_mutex &m)
 All checks from acquire using mutex.state were moved here. More...
 
bool __TBB_EXPORTED_METHOD internal_try_acquire (recursive_mutex &m)
 All checks from try_acquire using mutex.state were moved here. More...
 
void __TBB_EXPORTED_METHOD internal_release ()
 All checks from release using mutex.state were moved here. More...
 
- Private Member Functions inherited from tbb::internal::no_copy
 no_copy (const no_copy &)=delete
 
 no_copy ()=default
 

Private Attributes

mutexmy_mutex
 The pointer to the current mutex to work. More...
 
recursive_mutexmy_mutex
 The pointer to the current recursive_mutex to work. More...
 

Friends

class mutex
 
class recursive_mutex
 

Detailed Description

The scoped locking pattern.

It helps to avoid the common problem of forgetting to release lock. It also nicely provides the "node" for queuing locks.

Definition at line 85 of file mutex.h.

Constructor & Destructor Documentation

tbb::scoped_lock::scoped_lock ( )
inline

Construct lock that has not acquired a mutex.

Definition at line 88 of file mutex.h.

88 : my_mutex(NULL) {};
mutex * my_mutex
The pointer to the current mutex to work.
Definition: mutex.h:135
tbb::scoped_lock::scoped_lock ( mutex mutex)
inline

Acquire lock on given mutex.

Definition at line 91 of file mutex.h.

References tbb::acquire.

91  {
92  acquire( mutex );
93  }
void acquire(mutex &mutex)
Acquire lock on given mutex.
Definition: mutex.h:102
friend class mutex
Definition: mutex.h:146
tbb::scoped_lock::~scoped_lock ( )
inline

Release lock (if lock is held).

Definition at line 96 of file mutex.h.

References tbb::release.

96  {
97  if( my_mutex )
98  release();
99  }
void release()
Release lock.
Definition: mutex.h:124
mutex * my_mutex
The pointer to the current mutex to work.
Definition: mutex.h:135
tbb::scoped_lock::scoped_lock ( )
inline

Construct lock that has not acquired a recursive_mutex.

Definition at line 97 of file recursive_mutex.h.

97 : my_mutex(NULL) {};
mutex * my_mutex
The pointer to the current mutex to work.
Definition: mutex.h:135
tbb::scoped_lock::scoped_lock ( recursive_mutex mutex)
inline

Acquire lock on given mutex.

Definition at line 100 of file recursive_mutex.h.

References tbb::acquire.

100  {
101 #if TBB_USE_ASSERT
102  my_mutex = &mutex;
103 #endif /* TBB_USE_ASSERT */
104  acquire( mutex );
105  }
void acquire(mutex &mutex)
Acquire lock on given mutex.
Definition: mutex.h:102
mutex * my_mutex
The pointer to the current mutex to work.
Definition: mutex.h:135
friend class mutex
Definition: mutex.h:146
tbb::scoped_lock::~scoped_lock ( )
inline

Release lock (if lock is held).

Definition at line 108 of file recursive_mutex.h.

References tbb::release.

108  {
109  if( my_mutex )
110  release();
111  }
void release()
Release lock.
Definition: mutex.h:124
mutex * my_mutex
The pointer to the current mutex to work.
Definition: mutex.h:135

Member Function Documentation

void tbb::scoped_lock::acquire ( mutex mutex)
inline

Acquire lock on given mutex.

Definition at line 102 of file mutex.h.

102  {
103 #if TBB_USE_ASSERT
105 #else
106  mutex.lock();
107  my_mutex = &mutex;
108 #endif /* TBB_USE_ASSERT */
109  }
mutex * my_mutex
The pointer to the current mutex to work.
Definition: mutex.h:135
void __TBB_EXPORTED_METHOD internal_acquire(mutex &m)
All checks from acquire using mutex.state were moved here.
friend class mutex
Definition: mutex.h:146
void tbb::scoped_lock::acquire ( recursive_mutex mutex)
inline

Acquire lock on given mutex.

Definition at line 114 of file recursive_mutex.h.

114  {
115 #if TBB_USE_ASSERT
117 #else
118  my_mutex = &mutex;
119  mutex.lock();
120 #endif /* TBB_USE_ASSERT */
121  }
mutex * my_mutex
The pointer to the current mutex to work.
Definition: mutex.h:135
void __TBB_EXPORTED_METHOD internal_acquire(mutex &m)
All checks from acquire using mutex.state were moved here.
friend class mutex
Definition: mutex.h:146
void __TBB_EXPORTED_METHOD tbb::scoped_lock::internal_acquire ( mutex m)
private

All checks from acquire using mutex.state were moved here.

void __TBB_EXPORTED_METHOD tbb::scoped_lock::internal_acquire ( recursive_mutex m)
private

All checks from acquire using mutex.state were moved here.

void __TBB_EXPORTED_METHOD tbb::scoped_lock::internal_release ( )
private

All checks from release using mutex.state were moved here.

void __TBB_EXPORTED_METHOD tbb::scoped_lock::internal_release ( )
private

All checks from release using mutex.state were moved here.

bool __TBB_EXPORTED_METHOD tbb::scoped_lock::internal_try_acquire ( mutex m)
private

All checks from try_acquire using mutex.state were moved here.

bool __TBB_EXPORTED_METHOD tbb::scoped_lock::internal_try_acquire ( recursive_mutex m)
private

All checks from try_acquire using mutex.state were moved here.

void tbb::scoped_lock::release ( )
inline

Release lock.

Definition at line 124 of file mutex.h.

124  {
125 #if TBB_USE_ASSERT
126  internal_release ();
127 #else
128  my_mutex->unlock();
129  my_mutex = NULL;
130 #endif /* TBB_USE_ASSERT */
131  }
mutex * my_mutex
The pointer to the current mutex to work.
Definition: mutex.h:135
void __TBB_EXPORTED_METHOD internal_release()
All checks from release using mutex.state were moved here.
void tbb::scoped_lock::release ( )
inline

Release lock.

Definition at line 136 of file recursive_mutex.h.

136  {
137 #if TBB_USE_ASSERT
139 #else
140  my_mutex->unlock();
141  my_mutex = NULL;
142 #endif /* TBB_USE_ASSERT */
143  }
mutex * my_mutex
The pointer to the current mutex to work.
Definition: mutex.h:135
void __TBB_EXPORTED_METHOD internal_release()
All checks from release using mutex.state were moved here.
bool tbb::scoped_lock::try_acquire ( mutex mutex)
inline

Try acquire lock on given mutex.

Definition at line 112 of file mutex.h.

112  {
113 #if TBB_USE_ASSERT
114  return internal_try_acquire (mutex);
115 #else
116  bool result = mutex.try_lock();
117  if( result )
118  my_mutex = &mutex;
119  return result;
120 #endif /* TBB_USE_ASSERT */
121  }
mutex * my_mutex
The pointer to the current mutex to work.
Definition: mutex.h:135
bool __TBB_EXPORTED_METHOD internal_try_acquire(mutex &m)
All checks from try_acquire using mutex.state were moved here.
friend class mutex
Definition: mutex.h:146
bool tbb::scoped_lock::try_acquire ( recursive_mutex mutex)
inline

Try acquire lock on given recursive_mutex.

Definition at line 124 of file recursive_mutex.h.

124  {
125 #if TBB_USE_ASSERT
126  return internal_try_acquire( mutex );
127 #else
128  bool result = mutex.try_lock();
129  if( result )
130  my_mutex = &mutex;
131  return result;
132 #endif /* TBB_USE_ASSERT */
133  }
mutex * my_mutex
The pointer to the current mutex to work.
Definition: mutex.h:135
bool __TBB_EXPORTED_METHOD internal_try_acquire(mutex &m)
All checks from try_acquire using mutex.state were moved here.
friend class mutex
Definition: mutex.h:146

Friends And Related Function Documentation

friend class mutex
friend

Definition at line 146 of file mutex.h.

friend class recursive_mutex
friend

Definition at line 158 of file recursive_mutex.h.

Member Data Documentation

mutex* tbb::scoped_lock::my_mutex
private

The pointer to the current mutex to work.

Definition at line 135 of file mutex.h.

recursive_mutex* tbb::scoped_lock::my_mutex
private

The pointer to the current recursive_mutex to work.

Definition at line 147 of file recursive_mutex.h.


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

Copyright © 2005-2020 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.