tbb::spin_mutex Class Reference
Synchronization

A lock that occupies a single byte. More...

`#include <spin_mutex.h>`

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

## Classes

class | scoped_lock
| Represents acquisition of a mutex. More...

## Public Member Functions

| spin_mutex ()
| Construct unacquired lock. More...
void __TBB_EXPORTED_METHOD | internal_construct ()
| Internal constructor with ITT instrumentation. More...
void | lock ()
| Acquire lock. More...
bool | try_lock ()
| Try acquiring lock (non-blocking) More...
void | unlock ()
| Release lock. More...

## Static Public Attributes

static const bool | is_rw_mutex = false
static const bool | is_recursive_mutex = false
static const bool | is_fair_mutex = false

## Private Attributes

__TBB_atomic_flag | flag
| 0 if lock is released, 1 if lock is acquired. More...

## Friends

class | scoped_lock

## Detailed Description

A lock that occupies a single byte.

A spin_mutex is a spin mutex that fits in a single byte. It should be used only for locking short critical sections (typically less than 20 instructions) when fairness is not an issue. If zero-initialized, the mutex is considered unheld.

Definition at line 39 of file spin_mutex.h.

## Constructor & Destructor Documentation

## spin_mutex()

tbb::spin_mutex::spin_mutex | ( |  | ) |

inline

Construct unacquired lock.

Equivalent to zero-initialization of *this.

Definition at line 46 of file spin_mutex.h.

: flag(0) {
#if TBB_USE_THREADING_TOOLS
internal_construct();
#endif
}

References internal_construct().

Here is the call graph for this function:

## Member Function Documentation

## internal_construct()

void tbb::spin_mutex::internal_construct | ( |  | ) |

Internal constructor with ITT instrumentation.

Definition at line 50 of file spin_mutex.cpp.

{
ITT_SYNC_CREATE(this, _T("tbb::spin_mutex"), _T(""));
}

References _T, and ITT_SYNC_CREATE.

Referenced by spin_mutex().

Here is the caller graph for this function:

## lock()

void tbb::spin_mutex::lock | ( |  | ) |

inline

Acquire lock.

Definition at line 147 of file spin_mutex.h.

{
#if TBB_USE_THREADING_TOOLS
aligned_space<scoped_lock> tmp;
new(tmp.begin()) scoped_lock(*this);
#else
__TBB_LockByte(flag);
#endif /* TBB_USE_THREADING_TOOLS*/
}

References __TBB_LockByte(), flag, and scoped_lock.

Here is the call graph for this function:

## try_lock()

bool tbb::spin_mutex::try_lock | ( |  | ) |

inline

Try acquiring lock (non-blocking)

Return true if lock acquired; false otherwise.

Definition at line 158 of file spin_mutex.h.

{
#if TBB_USE_THREADING_TOOLS
aligned_space<scoped_lock> tmp;
return (new(tmp.begin()) scoped_lock)->internal_try_acquire(*this);
#else
return __TBB_TryLockByte(flag);
#endif /* TBB_USE_THREADING_TOOLS*/
}

References __TBB_TryLockByte(), and flag.

Here is the call graph for this function:

## unlock()

void tbb::spin_mutex::unlock | ( |  | ) |

inline

Release lock.

Definition at line 168 of file spin_mutex.h.

{
#if TBB_USE_THREADING_TOOLS
aligned_space<scoped_lock> tmp;
scoped_lock& s = *tmp.begin();
s.my_mutex = this;
s.internal_release();
#else
__TBB_UnlockByte(flag);
#endif /* TBB_USE_THREADING_TOOLS */
}

References __TBB_UnlockByte, flag, and s.

## Friends And Related Function Documentation

## scoped_lock

friend class scoped_lock

friend

Definition at line 179 of file spin_mutex.h.

Referenced by lock().

## Member Data Documentation

## flag

__TBB_atomic_flag tbb::spin_mutex::flag

private

0 if lock is released, 1 if lock is acquired.

Definition at line 41 of file spin_mutex.h.

Referenced by tbb::spin_mutex::scoped_lock::acquire(), tbb::spin_mutex::scoped_lock::internal_acquire(), tbb::spin_mutex::scoped_lock::internal_try_acquire(), lock(), tbb::spin_mutex::scoped_lock::release(), tbb::spin_mutex::scoped_lock::scoped_lock(), tbb::spin_mutex::scoped_lock::try_acquire(), try_lock(), unlock(), and tbb::spin_mutex::scoped_lock::~scoped_lock().

## is_fair_mutex

const bool tbb::spin_mutex::is_fair_mutex = false

static

Definition at line 142 of file spin_mutex.h.

## is_recursive_mutex

const bool tbb::spin_mutex::is_recursive_mutex = false

static

Definition at line 141 of file spin_mutex.h.

## is_rw_mutex

const bool tbb::spin_mutex::is_rw_mutex = false

static

Definition at line 140 of file spin_mutex.h.

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

- spin_mutex.h
- spin_mutex.cpp

__TBB_LockByte
__TBB_Flag __TBB_LockByte(__TBB_atomic_flag &flag)
Definition: tbb_machine.h:922
tbb::spin_mutex::scoped_lock
friend class scoped_lock
Definition: spin_mutex.h:179
__TBB_TryLockByte
bool __TBB_TryLockByte(__TBB_atomic_flag &flag)
Definition: tbb_machine.h:916
ITT_SYNC_CREATE
#define ITT_SYNC_CREATE(obj, type, name)
Definition: itt_notify.h:115
__TBB_UnlockByte
#define __TBB_UnlockByte
Definition: gcc_generic.h:211
_T
#define _T(string_literal)
Standard Windows style macro to markup the string literals.
Definition: itt_notify.h:59
s
void const char const char int ITT_FORMAT __itt_group_sync s
Definition: ittnotify_static.h:91
tbb::spin_mutex::internal_construct
void __TBB_EXPORTED_METHOD internal_construct()
Internal constructor with ITT instrumentation.
Definition: spin_mutex.cpp:50
tbb::spin_mutex::flag
__TBB_atomic_flag flag
0 if lock is released, 1 if lock is acquired.
Definition: spin_mutex.h:41

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.