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

Constructor & Destructor Documentation

◆ critical_section_v4()

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

Definition at line 47 of file critical_section.h.

References internal_construct().

47  {
48 #if _WIN32||_WIN64
49  InitializeCriticalSectionEx( &my_impl, 4000, 0 );
50 #else
51  pthread_mutex_init(&my_impl, NULL);
52 #endif
54  }
void __TBB_EXPORTED_METHOD internal_construct()
Here is the call graph for this function:

◆ ~critical_section_v4()

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

Definition at line 56 of file critical_section.h.

References __TBB_ASSERT, and id.

56  {
57  __TBB_ASSERT(my_tid == tbb_thread::id(), "Destroying a still-held critical section");
58 #if _WIN32||_WIN64
59  DeleteCriticalSection(&my_impl);
60 #else
61  pthread_mutex_destroy(&my_impl);
62 #endif
63  }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
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

Member Function Documentation

◆ internal_construct()

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

Definition at line 23 of file critical_section.cpp.

References _T, ITT_SYNC_CREATE, and my_impl.

Referenced by critical_section_v4().

23  {
24  ITT_SYNC_CREATE(&my_impl, _T("ppl::critical_section"), _T(""));
25 }
#define ITT_SYNC_CREATE(obj, type, name)
Definition: itt_notify.h:119
#define _T(string_literal)
Standard Windows style macro to markup the string literals.
Definition: itt_notify.h:62
Here is the caller graph for this function:

◆ lock()

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

Definition at line 78 of file critical_section.h.

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

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

78  {
80  if(local_tid == my_tid) throw_exception( eid_improper_lock );
81 #if _WIN32||_WIN64
82  EnterCriticalSection( &my_impl );
83 #else
84  int rval = pthread_mutex_lock(&my_impl);
85  __TBB_ASSERT_EX(!rval, "critical_section::lock: pthread_mutex_lock failed");
86 #endif
88  my_tid = local_tid;
89  }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
#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
tbb_thread::id get_id()
Definition: tbb_thread.h:317
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
void throw_exception(exception_id eid)
Versionless convenience wrapper for throw_exception_v4()
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 91 of file critical_section.h.

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

91  {
92  bool gotlock;
94  if(local_tid == my_tid) return false;
95 #if _WIN32||_WIN64
96  gotlock = TryEnterCriticalSection( &my_impl ) != 0;
97 #else
98  int rval = pthread_mutex_trylock(&my_impl);
99  // valid returns are 0 (locked) and [EBUSY]
100  __TBB_ASSERT(rval == 0 || rval == EBUSY, "critical_section::trylock: pthread_mutex_trylock failed");
101  gotlock = rval == 0;
102 #endif
103  if(gotlock) {
104  my_tid = local_tid;
105  }
106  return gotlock;
107  }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
tbb_thread::id get_id()
Definition: tbb_thread.h:317
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
Here is the call graph for this function:

◆ unlock()

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

Definition at line 109 of file critical_section.h.

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

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

109  {
110  __TBB_ASSERT(this_tbb_thread::get_id() == my_tid, "thread unlocking critical_section is not thread that locked it");
112 #if _WIN32||_WIN64
113  LeaveCriticalSection( &my_impl );
114 #else
115  int rval = pthread_mutex_unlock(&my_impl);
116  __TBB_ASSERT_EX(!rval, "critical_section::unlock: pthread_mutex_unlock failed");
117 #endif
118  }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
#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
tbb_thread::id get_id()
Definition: tbb_thread.h:317
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
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 122 of file critical_section.h.

◆ is_recursive_mutex

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

Definition at line 121 of file critical_section.h.

◆ is_rw_mutex

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

Definition at line 120 of file critical_section.h.

◆ my_impl

pthread_mutex_t tbb::internal::critical_section_v4::my_impl
private

Definition at line 40 of file critical_section.h.

Referenced by internal_construct().

◆ my_tid

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

Definition at line 42 of file critical_section.h.


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.