21 #ifndef __TBB_mutex_padding_H 22 #define __TBB_mutex_padding_H 29 namespace interface7 {
32 static const size_t cache_line_size = 64;
38 template<
typename Mutex>
39 class padded_mutex<Mutex,false> : tbb::internal::mutex_copy_deprecated_and_disabled {
40 typedef long pad_type;
41 pad_type my_pad[((
sizeof(Mutex)+cache_line_size-1)/cache_line_size+1)*cache_line_size/
sizeof(pad_type)];
43 Mutex *impl() {
return (Mutex *)((uintptr_t(
this)|(cache_line_size-1))+1);}
46 static const bool is_rw_mutex = Mutex::is_rw_mutex;
47 static const bool is_recursive_mutex = Mutex::is_recursive_mutex;
48 static const bool is_fair_mutex = Mutex::is_fair_mutex;
54 class scoped_lock : tbb::internal::no_copy {
55 typename Mutex::scoped_lock my_scoped_lock;
57 scoped_lock() : my_scoped_lock() {}
58 scoped_lock(
padded_mutex& m ) : my_scoped_lock(*m.impl()) { }
62 bool try_acquire(
padded_mutex& m ) {
return my_scoped_lock.try_acquire(*m.impl()); }
63 void release() { my_scoped_lock.release(); }
67 template<
typename Mutex>
68 class padded_mutex<Mutex,true> : tbb::internal::mutex_copy_deprecated_and_disabled {
69 typedef long pad_type;
70 pad_type my_pad[((
sizeof(Mutex)+cache_line_size-1)/cache_line_size+1)*cache_line_size/
sizeof(pad_type)];
72 Mutex *impl() {
return (Mutex *)((uintptr_t(
this)|(cache_line_size-1))+1);}
75 static const bool is_rw_mutex = Mutex::is_rw_mutex;
76 static const bool is_recursive_mutex = Mutex::is_recursive_mutex;
77 static const bool is_fair_mutex = Mutex::is_fair_mutex;
83 class scoped_lock : tbb::internal::no_copy {
84 typename Mutex::scoped_lock my_scoped_lock;
86 scoped_lock() : my_scoped_lock() {}
87 scoped_lock(
padded_mutex& m,
bool write =
true ) : my_scoped_lock(*m.impl(),write) { }
90 void acquire(
padded_mutex& m,
bool write =
true ) { my_scoped_lock.acquire(*m.impl(),write); }
91 bool try_acquire(
padded_mutex& m,
bool write =
true ) {
return my_scoped_lock.try_acquire(*m.impl(),write); }
92 bool upgrade_to_writer() {
return my_scoped_lock.upgrade_to_writer(); }
93 bool downgrade_to_reader() {
return my_scoped_lock.downgrade_to_reader(); }
94 void release() { my_scoped_lock.release(); }
Acquire.
Definition: atomic.h:47
Definition: _mutex_padding.h:36
Definition: _flow_graph_async_msg_impl.h:32
Release.
Definition: atomic.h:49
The namespace tbb contains all components of the library.
Definition: parallel_for.h:44