Home ⌂Doc Index ◂Up ▴
Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb::spin_mutex::scoped_lock Class Reference

Represents acquisition of a mutex. More...

#include <spin_mutex.h>

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

Public Member Functions

 scoped_lock ()
 Construct without acquiring a mutex. More...
 
 scoped_lock (spin_mutex &m)
 Construct and acquire lock on a mutex. More...
 
void acquire (spin_mutex &m)
 Acquire lock. More...
 
bool try_acquire (spin_mutex &m)
 Try acquiring lock (non-blocking) More...
 
void release ()
 Release lock. More...
 
 ~scoped_lock ()
 Destroy lock. If holding a lock, releases the lock first. More...
 

Private Member Functions

void __TBB_EXPORTED_METHOD internal_acquire (spin_mutex &m)
 Like acquire, but with ITT instrumentation. More...
 
bool __TBB_EXPORTED_METHOD internal_try_acquire (spin_mutex &m)
 Like try_acquire, but with ITT instrumentation. More...
 
void __TBB_EXPORTED_METHOD internal_release ()
 Like release, but with ITT instrumentation. More...
 
- Private Member Functions inherited from tbb::internal::no_copy
 no_copy (const no_copy &)=delete
 
 no_copy ()=default
 

Private Attributes

spin_mutexmy_mutex
 Points to currently held mutex, or NULL if no lock is held. More...
 
__TBB_Flag my_unlock_value
 Value to store into spin_mutex::flag to unlock the mutex. More...
 

Friends

class spin_mutex
 

Detailed Description

Represents acquisition of a mutex.

Definition at line 53 of file spin_mutex.h.

Constructor & Destructor Documentation

◆ scoped_lock() [1/2]

tbb::spin_mutex::scoped_lock::scoped_lock ( )
inline

Construct without acquiring a mutex.

Definition at line 77 of file spin_mutex.h.

77 : my_mutex(NULL), my_unlock_value(0) {}
spin_mutex * my_mutex
Points to currently held mutex, or NULL if no lock is held.
Definition: spin_mutex.h:56
__TBB_Flag my_unlock_value
Value to store into spin_mutex::flag to unlock the mutex.
Definition: spin_mutex.h:62

◆ scoped_lock() [2/2]

tbb::spin_mutex::scoped_lock::scoped_lock ( spin_mutex m)
inline

Construct and acquire lock on a mutex.

Definition at line 80 of file spin_mutex.h.

80  : my_unlock_value(0) {
82 #if TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT
83  my_mutex=NULL;
85 #else
86  my_mutex=&m;
87  __TBB_LockByte(m.flag);
88 #endif /* TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT*/
89  }
void __TBB_EXPORTED_METHOD internal_acquire(spin_mutex &m)
Like acquire, but with ITT instrumentation.
Definition: spin_mutex.cpp:24
void suppress_unused_warning(const T1 &)
Utility template function to prevent "unused" warnings by various compilers.
Definition: tbb_stddef.h:398
__TBB_Flag __TBB_LockByte(__TBB_atomic_flag &flag)
Definition: tbb_machine.h:919
spin_mutex * my_mutex
Points to currently held mutex, or NULL if no lock is held.
Definition: spin_mutex.h:56
__TBB_Flag my_unlock_value
Value to store into spin_mutex::flag to unlock the mutex.
Definition: spin_mutex.h:62

References __TBB_LockByte(), tbb::spin_mutex::flag, internal_acquire(), my_mutex, my_unlock_value, and tbb::internal::suppress_unused_warning().

Here is the call graph for this function:

◆ ~scoped_lock()

tbb::spin_mutex::scoped_lock::~scoped_lock ( )
inline

Destroy lock. If holding a lock, releases the lock first.

Definition at line 125 of file spin_mutex.h.

125  {
126  if( my_mutex ) {
127 #if TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT
129 #else
131 #endif /* TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT */
132  }
133  }
void __TBB_EXPORTED_METHOD internal_release()
Like release, but with ITT instrumentation.
Definition: spin_mutex.cpp:32
#define __TBB_UnlockByte
Definition: gcc_generic.h:211
__TBB_atomic_flag flag
0 if lock is released, 1 if lock is acquired.
Definition: spin_mutex.h:41
spin_mutex * my_mutex
Points to currently held mutex, or NULL if no lock is held.
Definition: spin_mutex.h:56

References __TBB_UnlockByte, tbb::spin_mutex::flag, internal_release(), and my_mutex.

Here is the call graph for this function:

Member Function Documentation

◆ acquire()

void tbb::spin_mutex::scoped_lock::acquire ( spin_mutex m)
inline

Acquire lock.

Definition at line 92 of file spin_mutex.h.

92  {
93 #if TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT
95 #else
96  my_mutex = &m;
97  __TBB_LockByte(m.flag);
98 #endif /* TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT*/
99  }
void __TBB_EXPORTED_METHOD internal_acquire(spin_mutex &m)
Like acquire, but with ITT instrumentation.
Definition: spin_mutex.cpp:24
__TBB_Flag __TBB_LockByte(__TBB_atomic_flag &flag)
Definition: tbb_machine.h:919
spin_mutex * my_mutex
Points to currently held mutex, or NULL if no lock is held.
Definition: spin_mutex.h:56

References __TBB_LockByte(), tbb::spin_mutex::flag, internal_acquire(), and my_mutex.

Here is the call graph for this function:

◆ internal_acquire()

void tbb::spin_mutex::scoped_lock::internal_acquire ( spin_mutex m)
private

Like acquire, but with ITT instrumentation.

Definition at line 24 of file spin_mutex.cpp.

24  {
25  __TBB_ASSERT( !my_mutex, "already holding a lock on a spin_mutex" );
26  ITT_NOTIFY(sync_prepare, &m);
27  __TBB_LockByte(m.flag);
28  my_mutex = &m;
29  ITT_NOTIFY(sync_acquired, &m);
30 }
__TBB_Flag __TBB_LockByte(__TBB_atomic_flag &flag)
Definition: tbb_machine.h:919
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
#define ITT_NOTIFY(name, obj)
Definition: itt_notify.h:112
spin_mutex * my_mutex
Points to currently held mutex, or NULL if no lock is held.
Definition: spin_mutex.h:56

References __TBB_ASSERT, __TBB_LockByte(), tbb::spin_mutex::flag, ITT_NOTIFY, and my_mutex.

Referenced by acquire(), and scoped_lock().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ internal_release()

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

Like release, but with ITT instrumentation.

Definition at line 32 of file spin_mutex.cpp.

32  {
33  __TBB_ASSERT( my_mutex, "release on spin_mutex::scoped_lock that is not holding a lock" );
34 
37  my_mutex = NULL;
38 }
#define __TBB_UnlockByte
Definition: gcc_generic.h:211
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p sync_releasing
__TBB_atomic_flag flag
0 if lock is released, 1 if lock is acquired.
Definition: spin_mutex.h:41
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
#define ITT_NOTIFY(name, obj)
Definition: itt_notify.h:112
spin_mutex * my_mutex
Points to currently held mutex, or NULL if no lock is held.
Definition: spin_mutex.h:56

References __TBB_ASSERT, __TBB_UnlockByte, ITT_NOTIFY, and sync_releasing.

Referenced by release(), and ~scoped_lock().

Here is the caller graph for this function:

◆ internal_try_acquire()

bool tbb::spin_mutex::scoped_lock::internal_try_acquire ( spin_mutex m)
private

Like try_acquire, but with ITT instrumentation.

Definition at line 40 of file spin_mutex.cpp.

40  {
41  __TBB_ASSERT( !my_mutex, "already holding a lock on a spin_mutex" );
42  bool result = bool( __TBB_TryLockByte(m.flag) );
43  if( result ) {
44  my_mutex = &m;
45  ITT_NOTIFY(sync_acquired, &m);
46  }
47  return result;
48 }
bool __TBB_TryLockByte(__TBB_atomic_flag &flag)
Definition: tbb_machine.h:913
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
#define ITT_NOTIFY(name, obj)
Definition: itt_notify.h:112
spin_mutex * my_mutex
Points to currently held mutex, or NULL if no lock is held.
Definition: spin_mutex.h:56

References __TBB_ASSERT, __TBB_TryLockByte(), tbb::spin_mutex::flag, and ITT_NOTIFY.

Referenced by try_acquire().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ release()

void tbb::spin_mutex::scoped_lock::release ( )
inline

Release lock.

Definition at line 115 of file spin_mutex.h.

115  {
116 #if TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT
118 #else
120  my_mutex = NULL;
121 #endif /* TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT */
122  }
void __TBB_EXPORTED_METHOD internal_release()
Like release, but with ITT instrumentation.
Definition: spin_mutex.cpp:32
#define __TBB_UnlockByte
Definition: gcc_generic.h:211
__TBB_atomic_flag flag
0 if lock is released, 1 if lock is acquired.
Definition: spin_mutex.h:41
spin_mutex * my_mutex
Points to currently held mutex, or NULL if no lock is held.
Definition: spin_mutex.h:56

References __TBB_UnlockByte, tbb::spin_mutex::flag, internal_release(), and my_mutex.

Here is the call graph for this function:

◆ try_acquire()

bool tbb::spin_mutex::scoped_lock::try_acquire ( spin_mutex m)
inline

Try acquiring lock (non-blocking)

Return true if lock acquired; false otherwise.

Definition at line 103 of file spin_mutex.h.

103  {
104 #if TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT
105  return internal_try_acquire(m);
106 #else
107  bool result = __TBB_TryLockByte(m.flag);
108  if( result )
109  my_mutex = &m;
110  return result;
111 #endif /* TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT*/
112  }
bool __TBB_TryLockByte(__TBB_atomic_flag &flag)
Definition: tbb_machine.h:913
bool __TBB_EXPORTED_METHOD internal_try_acquire(spin_mutex &m)
Like try_acquire, but with ITT instrumentation.
Definition: spin_mutex.cpp:40
spin_mutex * my_mutex
Points to currently held mutex, or NULL if no lock is held.
Definition: spin_mutex.h:56

References __TBB_TryLockByte(), tbb::spin_mutex::flag, internal_try_acquire(), and my_mutex.

Here is the call graph for this function:

Friends And Related Function Documentation

◆ spin_mutex

friend class spin_mutex
friend

Definition at line 73 of file spin_mutex.h.

Member Data Documentation

◆ my_mutex

spin_mutex* tbb::spin_mutex::scoped_lock::my_mutex
private

Points to currently held mutex, or NULL if no lock is held.

Definition at line 56 of file spin_mutex.h.

Referenced by acquire(), internal_acquire(), release(), scoped_lock(), try_acquire(), and ~scoped_lock().

◆ my_unlock_value

__TBB_Flag tbb::spin_mutex::scoped_lock::my_unlock_value
private

Value to store into spin_mutex::flag to unlock the mutex.

This variable is no longer used. Instead, 0 and 1 are used to represent that the lock is free and acquired, respectively. We keep the member variable here to ensure backward compatibility

Definition at line 62 of file spin_mutex.h.

Referenced by scoped_lock().


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.