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_mutex * | my_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.

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

## 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.

: my_unlock_value(0) {
internal::suppress_unused_warning(my_unlock_value);
#if TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT
my_mutex=NULL;
internal_acquire(m);
#else
my_mutex=&m;
__TBB_LockByte(m.flag);
#endif /* TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT*/
}
__TBB_LockByte
__TBB_Flag __TBB_LockByte(__TBB_atomic_flag &flag)
Definition: tbb_machine.h:922
tbb::internal::suppress_unused_warning
void suppress_unused_warning(const T1 &)
Utility template function to prevent "unused" warnings by various compilers.
Definition: tbb_stddef.h:398
tbb::spin_mutex::scoped_lock::internal_acquire
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(), 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.

{
if( my_mutex ) {
#if TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT
internal_release();
#else
__TBB_UnlockByte(my_mutex->flag);
#endif /* TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT */
}
}
__TBB_UnlockByte
#define __TBB_UnlockByte
Definition: gcc_generic.h:211
tbb::spin_mutex::flag
__TBB_atomic_flag flag
0 if lock is released, 1 if lock is acquired.
Definition: spin_mutex.h:41
tbb::spin_mutex::scoped_lock::internal_release
void __TBB_EXPORTED_METHOD internal_release()
Like release, but with ITT instrumentation.
Definition: spin_mutex.cpp:32

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.

{
#if TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT
internal_acquire(m);
#else
my_mutex = &m;
__TBB_LockByte(m.flag);
#endif /* TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT*/
}

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.

{
__TBB_ASSERT( !my_mutex, "already holding a lock on a spin_mutex" );
ITT_NOTIFY(sync_prepare, &m);
__TBB_LockByte(m.flag);
my_mutex = &m;
ITT_NOTIFY(sync_acquired, &m);
}
__TBB_ASSERT
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
ITT_NOTIFY
#define ITT_NOTIFY(name, obj)
Definition: itt_notify.h:112

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.

{
__TBB_ASSERT( my_mutex, "release on spin_mutex::scoped_lock that is not holding a lock" );
ITT_NOTIFY(sync_releasing, my_mutex);
__TBB_UnlockByte(my_mutex->flag);
my_mutex = NULL;
}
sync_releasing
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
Definition: ittnotify_static.h:104

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.

{
__TBB_ASSERT( !my_mutex, "already holding a lock on a spin_mutex" );
bool result = bool( __TBB_TryLockByte(m.flag) );
if( result ) {
my_mutex = &m;
ITT_NOTIFY(sync_acquired, &m);
}
return result;
}
__TBB_TryLockByte
bool __TBB_TryLockByte(__TBB_atomic_flag &flag)
Definition: tbb_machine.h:916

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.

{
#if TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT
internal_release();
#else
__TBB_UnlockByte(my_mutex->flag);
my_mutex = NULL;
#endif /* TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT */
}

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.

{
#if TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT
return internal_try_acquire(m);
#else
bool result = __TBB_TryLockByte(m.flag);
if( result )
my_mutex = &m;
return result;
#endif /* TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT*/
}
tbb::spin_mutex::scoped_lock::internal_try_acquire
bool __TBB_EXPORTED_METHOD internal_try_acquire(spin_mutex &m)
Like try_acquire, but with ITT instrumentation.
Definition: spin_mutex.cpp:40

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:

- spin_mutex.h
- spin_mutex.cpp

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.