File indexing completed on 2025-01-18 10:12:50
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef __TBB__x86_eliding_mutex_impl_H
0018 #define __TBB__x86_eliding_mutex_impl_H
0019
0020 #ifndef __TBB_spin_mutex_H
0021 #error Do not #include this internal file directly; use public TBB headers instead.
0022 #endif
0023
0024 #if ( __TBB_x86_32 || __TBB_x86_64 )
0025
0026 namespace tbb {
0027 namespace interface7 {
0028 namespace internal {
0029
0030 template<typename Mutex, bool is_rw>
0031 class padded_mutex;
0032
0033
0034
0035
0036
0037
0038
0039
0040 class x86_eliding_mutex : tbb::internal::mutex_copy_deprecated_and_disabled {
0041
0042 __TBB_atomic_flag flag;
0043
0044 friend class padded_mutex<x86_eliding_mutex, false>;
0045
0046 public:
0047
0048
0049 x86_eliding_mutex() : flag(0) {}
0050
0051
0052
0053 #if __TBB_USE_X86_ELIDING_MUTEX || __TBB_GCC_VERSION < 40000
0054 #else
0055
0056
0057
0058 private:
0059 #endif
0060
0061
0062 class scoped_lock : tbb::internal::no_copy {
0063 private:
0064
0065 x86_eliding_mutex* my_mutex;
0066
0067 public:
0068
0069 scoped_lock() : my_mutex(NULL) {}
0070
0071
0072 scoped_lock( x86_eliding_mutex& m ) : my_mutex(NULL) { acquire(m); }
0073
0074
0075 void acquire( x86_eliding_mutex& m ) {
0076 __TBB_ASSERT( !my_mutex, "already holding a lock" );
0077
0078 my_mutex=&m;
0079 my_mutex->lock();
0080 }
0081
0082
0083
0084 bool try_acquire( x86_eliding_mutex& m ) {
0085 __TBB_ASSERT( !my_mutex, "already holding a lock" );
0086
0087 bool result = m.try_lock();
0088 if( result ) {
0089 my_mutex = &m;
0090 }
0091 return result;
0092 }
0093
0094
0095 void release() {
0096 __TBB_ASSERT( my_mutex, "release on scoped_lock that is not holding a lock" );
0097
0098 my_mutex->unlock();
0099 my_mutex = NULL;
0100 }
0101
0102
0103 ~scoped_lock() {
0104 if( my_mutex ) {
0105 release();
0106 }
0107 }
0108 };
0109 #if __TBB_USE_X86_ELIDING_MUTEX || __TBB_GCC_VERSION < 40000
0110 #else
0111 public:
0112 #endif
0113
0114
0115 static const bool is_rw_mutex = false;
0116 static const bool is_recursive_mutex = false;
0117 static const bool is_fair_mutex = false;
0118
0119
0120
0121
0122 void lock() {
0123 __TBB_LockByteElided(flag);
0124 }
0125
0126
0127
0128 bool try_lock() {
0129 return __TBB_TryLockByteElided(flag);
0130 }
0131
0132
0133 void unlock() {
0134 __TBB_UnlockByteElided( flag );
0135 }
0136 };
0137
0138 }
0139 }
0140 }
0141
0142 #endif
0143
0144 #endif