Home ⌂Doc Index ◂Up ▴
Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
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.

61  {
62 #if _WIN32||_WIN64
63  InitializeCriticalSectionEx( &my_impl, 4000, 0 );
64 #else
65  pthread_mutex_init(&my_impl, NULL);
66 #endif
68  }
void __TBB_EXPORTED_METHOD 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.

70  {
71  __TBB_ASSERT(my_tid == tbb_thread::id(), "Destroying a still-held critical section");
72 #if _WIN32||_WIN64
73  DeleteCriticalSection(&my_impl);
74 #else
75  pthread_mutex_destroy(&my_impl);
76 #endif
77  }
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
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165

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.

23  {
24  ITT_SYNC_CREATE(&my_impl, _T("ppl::critical_section"), _T(""));
25 }
#define _T(string_literal)
Standard Windows style macro to markup the string literals.
Definition: itt_notify.h:59
#define ITT_SYNC_CREATE(obj, type, name)
Definition: itt_notify.h:115

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.

92  {
94  if(local_tid == my_tid) throw_exception( eid_improper_lock );
95 #if _WIN32||_WIN64
96  EnterCriticalSection( &my_impl );
97 #else
98  int rval = pthread_mutex_lock(&my_impl);
99  __TBB_ASSERT_EX(!rval, "critical_section::lock: pthread_mutex_lock failed");
100 #endif
101  __TBB_ASSERT(my_tid == tbb_thread::id(), NULL);
102  my_tid = local_tid;
103  }
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
__TBB_DEPRECATED_IN_VERBOSE_MODE tbb_thread::id get_id()
Definition: tbb_thread.h:331
#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
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
void throw_exception(exception_id eid)
Versionless convenience wrapper for throw_exception_v4()

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.

105  {
106  bool gotlock;
108  if(local_tid == my_tid) return false;
109 #if _WIN32||_WIN64
110  gotlock = TryEnterCriticalSection( &my_impl ) != 0;
111 #else
112  int rval = pthread_mutex_trylock(&my_impl);
113  // valid returns are 0 (locked) and [EBUSY]
114  __TBB_ASSERT(rval == 0 || rval == EBUSY, "critical_section::trylock: pthread_mutex_trylock failed");
115  gotlock = rval == 0;
116 #endif
117  if(gotlock) {
118  my_tid = local_tid;
119  }
120  return gotlock;
121  }
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
__TBB_DEPRECATED_IN_VERBOSE_MODE tbb_thread::id get_id()
Definition: tbb_thread.h:331
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165

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.

123  {
124  __TBB_ASSERT(this_tbb_thread::get_id() == my_tid, "thread unlocking critical_section is not thread that locked it");
126 #if _WIN32||_WIN64
127  LeaveCriticalSection( &my_impl );
128 #else
129  int rval = pthread_mutex_unlock(&my_impl);
130  __TBB_ASSERT_EX(!rval, "critical_section::unlock: pthread_mutex_unlock failed");
131 #endif
132  }
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
__TBB_DEPRECATED_IN_VERBOSE_MODE tbb_thread::id get_id()
Definition: tbb_thread.h:331
#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
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165

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

◆ 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:

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.