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 ()
 Allow default construction. More...
 

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 50 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 74 of file spin_mutex.h.

74 : 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:53
__TBB_Flag my_unlock_value
Value to store into spin_mutex::flag to unlock the mutex.
Definition: spin_mutex.h:59

◆ 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 77 of file spin_mutex.h.

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

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 122 of file spin_mutex.h.

122  {
123  if( my_mutex ) {
124 #if TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT
126 #else
128 #endif /* TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT */
129  }
130  }
__TBB_atomic_flag flag
0 if lock is released, 1 if lock is acquired.
Definition: spin_mutex.h:38
void __TBB_EXPORTED_METHOD internal_release()
Like release, but with ITT instrumentation.
Definition: spin_mutex.cpp:32
spin_mutex * my_mutex
Points to currently held mutex, or NULL if no lock is held.
Definition: spin_mutex.h:53
#define __TBB_UnlockByte
Definition: gcc_generic.h:211

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 89 of file spin_mutex.h.

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

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 }
spin_mutex * my_mutex
Points to currently held mutex, or NULL if no lock is held.
Definition: spin_mutex.h:53
__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:116

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 }
__TBB_atomic_flag flag
0 if lock is released, 1 if lock is acquired.
Definition: spin_mutex.h:38
spin_mutex * my_mutex
Points to currently held mutex, or NULL if no lock is held.
Definition: spin_mutex.h:53
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
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
#define ITT_NOTIFY(name, obj)
Definition: itt_notify.h:116
#define __TBB_UnlockByte
Definition: gcc_generic.h:211

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
spin_mutex * my_mutex
Points to currently held mutex, or NULL if no lock is held.
Definition: spin_mutex.h:53
#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:116

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 112 of file spin_mutex.h.

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

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 100 of file spin_mutex.h.

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

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 70 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 53 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 59 of file spin_mutex.h.

Referenced by scoped_lock().


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

Copyright © 2005-2019 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.