File indexing completed on 2025-01-18 10:12:59
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef __TBB_queuing_rw_mutex_H
0018 #define __TBB_queuing_rw_mutex_H
0019
0020 #define __TBB_queuing_rw_mutex_H_include_area
0021 #include "internal/_warning_suppress_enable_notice.h"
0022
0023 #include <cstring>
0024 #include "atomic.h"
0025 #include "tbb_profiling.h"
0026
0027 namespace tbb {
0028
0029
0030
0031
0032
0033 class queuing_rw_mutex : internal::mutex_copy_deprecated_and_disabled {
0034 public:
0035
0036 queuing_rw_mutex() {
0037 q_tail = NULL;
0038 #if TBB_USE_THREADING_TOOLS
0039 internal_construct();
0040 #endif
0041 }
0042
0043
0044 ~queuing_rw_mutex() {
0045 #if TBB_USE_ASSERT
0046 __TBB_ASSERT( !q_tail, "destruction of an acquired mutex");
0047 #endif
0048 }
0049
0050
0051
0052
0053 class scoped_lock: internal::no_copy {
0054
0055 void initialize() {
0056 my_mutex = NULL;
0057 my_internal_lock = 0;
0058 my_going = 0;
0059 #if TBB_USE_ASSERT
0060 my_state = 0xFF;
0061 internal::poison_pointer(my_next);
0062 internal::poison_pointer(my_prev);
0063 #endif
0064 }
0065
0066 public:
0067
0068
0069 scoped_lock() {initialize();}
0070
0071
0072 scoped_lock( queuing_rw_mutex& m, bool write=true ) {
0073 initialize();
0074 acquire(m,write);
0075 }
0076
0077
0078 ~scoped_lock() {
0079 if( my_mutex ) release();
0080 }
0081
0082
0083 void acquire( queuing_rw_mutex& m, bool write=true );
0084
0085
0086 bool try_acquire( queuing_rw_mutex& m, bool write=true );
0087
0088
0089 void release();
0090
0091
0092
0093 bool upgrade_to_writer();
0094
0095
0096 bool downgrade_to_reader();
0097
0098 private:
0099
0100 queuing_rw_mutex* my_mutex;
0101
0102
0103 scoped_lock *__TBB_atomic my_prev, *__TBB_atomic my_next;
0104
0105 typedef unsigned char state_t;
0106
0107
0108 atomic<state_t> my_state;
0109
0110
0111
0112 unsigned char __TBB_atomic my_going;
0113
0114
0115 unsigned char my_internal_lock;
0116
0117
0118 void acquire_internal_lock();
0119
0120
0121
0122 bool try_acquire_internal_lock();
0123
0124
0125 void release_internal_lock();
0126
0127
0128 void wait_for_release_of_internal_lock();
0129
0130
0131 void unblock_or_wait_on_internal_lock( uintptr_t );
0132 };
0133
0134 void __TBB_EXPORTED_METHOD internal_construct();
0135
0136
0137 static const bool is_rw_mutex = true;
0138 static const bool is_recursive_mutex = false;
0139 static const bool is_fair_mutex = true;
0140
0141 private:
0142
0143 atomic<scoped_lock*> q_tail;
0144
0145 };
0146
0147 __TBB_DEFINE_PROFILING_SET_NAME(queuing_rw_mutex)
0148
0149 }
0150
0151 #include "internal/_warning_suppress_disable_notice.h"
0152 #undef __TBB_queuing_rw_mutex_H_include_area
0153
0154 #endif