tbb::internal::critical_section_v4 Class Reference

`#include <critical_section.h>`

Inheritance diagram for tbb::internal::critical_section_v4:
Collaboration diagram for tbb::internal::critical_section_v4:

## Classes

class | scoped_lock

## Public Member Functions

void __TBB_EXPORTED_METHOD | internal_construct ()
| critical_section_v4 ()
| ~critical_section_v4 ()
void | lock ()
bool | try_lock ()
void | unlock ()

## Static Public Attributes

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

## Private Attributes

pthread_mutex_t | my_impl
tbb_thread::id | my_tid

## Additional Inherited Members

Private Member Functions inherited from tbb::internal::no_copy
| no_copy (const no_copy &)=delete
| no_copy ()=default

## Detailed Description

Definition at line 50 of file critical_section.h.

## Constructor & Destructor Documentation

## critical_section_v4()

tbb::internal::critical_section_v4::critical_section_v4 | ( |  | ) |

inline

Definition at line 61 of file critical_section.h.

{
#if _WIN32||_WIN64
InitializeCriticalSectionEx( &my_impl, 4000, 0 );
#else
pthread_mutex_init(&my_impl, NULL);
#endif
internal_construct();
}

References internal_construct(), and my_impl.

Here is the call graph for this function:

## ~critical_section_v4()

tbb::internal::critical_section_v4::~critical_section_v4 | ( |  | ) |

inline

Definition at line 70 of file critical_section.h.

{
__TBB_ASSERT(my_tid == tbb_thread::id(), "Destroying a still-held critical section");
#if _WIN32||_WIN64
DeleteCriticalSection(&my_impl);
#else
pthread_mutex_destroy(&my_impl);
#endif
}

References __TBB_ASSERT, id, my_impl, and my_tid.

## Member Function Documentation

## internal_construct()

void tbb::internal::critical_section_v4::internal_construct | ( |  | ) |

Definition at line 23 of file critical_section.cpp.

{
ITT_SYNC_CREATE(&my_impl, _T("ppl::critical_section"), _T(""));
}

References _T, ITT_SYNC_CREATE, and my_impl.

Referenced by critical_section_v4().

Here is the caller graph for this function:

## lock()

void tbb::internal::critical_section_v4::lock | ( |  | ) |

inline

Definition at line 92 of file critical_section.h.

{
tbb_thread::id local_tid = this_tbb_thread::get_id();
if(local_tid == my_tid) throw_exception( eid_improper_lock );
#if _WIN32||_WIN64
EnterCriticalSection( &my_impl );
#else
int rval = pthread_mutex_lock(&my_impl);
__TBB_ASSERT_EX(!rval, "critical_section::lock: pthread_mutex_lock failed");
#endif
__TBB_ASSERT(my_tid == tbb_thread::id(), NULL);
my_tid = local_tid;
}

References __TBB_ASSERT, __TBB_ASSERT_EX, tbb::internal::eid_improper_lock, tbb::this_tbb_thread::get_id(), id, my_impl, my_tid, and tbb::internal::throw_exception().

Referenced by tbb::internal::critical_section_v4::scoped_lock::scoped_lock().

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

## try_lock()

bool tbb::internal::critical_section_v4::try_lock | ( |  | ) |

inline

Definition at line 105 of file critical_section.h.

{
bool gotlock;
tbb_thread::id local_tid = this_tbb_thread::get_id();
if(local_tid == my_tid) return false;
#if _WIN32||_WIN64
gotlock = TryEnterCriticalSection( &my_impl ) != 0;
#else
int rval = pthread_mutex_trylock(&my_impl);
// valid returns are 0 (locked) and [EBUSY]
__TBB_ASSERT(rval == 0 || rval == EBUSY, "critical_section::trylock: pthread_mutex_trylock failed");
gotlock = rval == 0;
#endif
if(gotlock) {
my_tid = local_tid;
}
return gotlock;
}

References __TBB_ASSERT, tbb::this_tbb_thread::get_id(), id, my_impl, and my_tid.

Here is the call graph for this function:

## unlock()

void tbb::internal::critical_section_v4::unlock | ( |  | ) |

inline

Definition at line 123 of file critical_section.h.

{
__TBB_ASSERT(this_tbb_thread::get_id() == my_tid, "thread unlocking critical_section is not thread that locked it");
my_tid = tbb_thread::id();
#if _WIN32||_WIN64
LeaveCriticalSection( &my_impl );
#else
int rval = pthread_mutex_unlock(&my_impl);
__TBB_ASSERT_EX(!rval, "critical_section::unlock: pthread_mutex_unlock failed");
#endif
}

References __TBB_ASSERT, __TBB_ASSERT_EX, tbb::this_tbb_thread::get_id(), id, my_impl, and my_tid.

Referenced by tbb::internal::critical_section_v4::scoped_lock::~scoped_lock().

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

## Member Data Documentation

## is_fair_mutex

const bool tbb::internal::critical_section_v4::is_fair_mutex = true

static

Definition at line 136 of file critical_section.h.

## is_recursive_mutex

const bool tbb::internal::critical_section_v4::is_recursive_mutex = false

static

Definition at line 135 of file critical_section.h.

## is_rw_mutex

const bool tbb::internal::critical_section_v4::is_rw_mutex = false

static

Definition at line 134 of file critical_section.h.

## my_impl

pthread_mutex_t tbb::internal::critical_section_v4::my_impl

private

Definition at line 54 of file critical_section.h.

Referenced by critical_section_v4(), internal_construct(), lock(), try_lock(), unlock(), and ~critical_section_v4().

## my_tid

tbb_thread::id tbb::internal::critical_section_v4::my_tid

private

Definition at line 56 of file critical_section.h.

Referenced by lock(), try_lock(), unlock(), and ~critical_section_v4().

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

- critical_section.h
- critical_section.cpp

tbb::internal::eid_improper_lock
Definition: tbb_exception.h:76
__TBB_ASSERT
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
id
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 void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id id
Definition: ittnotify_static.h:172
tbb::internal::throw_exception
void throw_exception(exception_id eid)
Versionless convenience wrapper for throw_exception_v4()
Definition: tbb_exception.h:105
tbb::this_tbb_thread::get_id
__TBB_DEPRECATED_VERBOSE tbb_thread::id get_id()
Definition: tbb_thread.h:331
tbb::internal::critical_section_v4::internal_construct
void __TBB_EXPORTED_METHOD internal_construct()
Definition: critical_section.cpp:23
ITT_SYNC_CREATE
#define ITT_SYNC_CREATE(obj, type, name)
Definition: itt_notify.h:115
_T
#define _T(string_literal)
Standard Windows style macro to markup the string literals.
Definition: itt_notify.h:59
tbb::internal::critical_section_v4::my_impl
pthread_mutex_t my_impl
Definition: critical_section.h:54
tbb::internal::critical_section_v4::my_tid
tbb_thread::id my_tid
Definition: critical_section.h:56
__TBB_ASSERT_EX
#define __TBB_ASSERT_EX(predicate, comment)
"Extended" version is useful to suppress warnings if a variable is only used with an assert
Definition: tbb_stddef.h:167

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.