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

Detailed Description

Definition at line 40 of file critical_section.h.

Constructor & Destructor Documentation

◆ critical_section_v4()

tbb::internal::critical_section_v4::critical_section_v4 ( )
inline

Definition at line 51 of file critical_section.h.

51  {
52 #if _WIN32||_WIN64
53  InitializeCriticalSectionEx( &my_impl, 4000, 0 );
54 #else
55  pthread_mutex_init(&my_impl, NULL);
56 #endif
58  }
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 60 of file critical_section.h.

60  {
61  __TBB_ASSERT(my_tid == tbb_thread::id(), "Destroying a still-held critical section");
62 #if _WIN32||_WIN64
63  DeleteCriticalSection(&my_impl);
64 #else
65  pthread_mutex_destroy(&my_impl);
66 #endif
67  }
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:169

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 27 of file critical_section.cpp.

27  {
28  ITT_SYNC_CREATE(&my_impl, _T("ppl::critical_section"), _T(""));
29 }
#define ITT_SYNC_CREATE(obj, type, name)
Definition: itt_notify.h:123
#define _T(string_literal)
Standard Windows style macro to markup the string literals.
Definition: itt_notify.h:66

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 82 of file critical_section.h.

82  {
84  if(local_tid == my_tid) throw_exception( eid_improper_lock );
85 #if _WIN32||_WIN64
86  EnterCriticalSection( &my_impl );
87 #else
88  int rval = pthread_mutex_lock(&my_impl);
89  __TBB_ASSERT_EX(!rval, "critical_section::lock: pthread_mutex_lock failed");
90 #endif
92  my_tid = local_tid;
93  }
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:169
#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:171
void throw_exception(exception_id eid)
Versionless convenience wrapper for throw_exception_v4()
tbb_thread::id get_id()
Definition: tbb_thread.h:321

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 95 of file critical_section.h.

95  {
96  bool gotlock;
98  if(local_tid == my_tid) return false;
99 #if _WIN32||_WIN64
100  gotlock = TryEnterCriticalSection( &my_impl ) != 0;
101 #else
102  int rval = pthread_mutex_trylock(&my_impl);
103  // valid returns are 0 (locked) and [EBUSY]
104  __TBB_ASSERT(rval == 0 || rval == EBUSY, "critical_section::trylock: pthread_mutex_trylock failed");
105  gotlock = rval == 0;
106 #endif
107  if(gotlock) {
108  my_tid = local_tid;
109  }
110  return gotlock;
111  }
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:169
tbb_thread::id get_id()
Definition: tbb_thread.h:321

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 113 of file critical_section.h.

113  {
114  __TBB_ASSERT(this_tbb_thread::get_id() == my_tid, "thread unlocking critical_section is not thread that locked it");
116 #if _WIN32||_WIN64
117  LeaveCriticalSection( &my_impl );
118 #else
119  int rval = pthread_mutex_unlock(&my_impl);
120  __TBB_ASSERT_EX(!rval, "critical_section::unlock: pthread_mutex_unlock failed");
121 #endif
122  }
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:169
#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:171
tbb_thread::id get_id()
Definition: tbb_thread.h:321

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 126 of file critical_section.h.

◆ is_recursive_mutex

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

Definition at line 125 of file critical_section.h.

◆ is_rw_mutex

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

Definition at line 124 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 46 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-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.