Changeset eef8dfb for libcfa/src/concurrency/mutex.cfa
- Timestamp:
- Jan 7, 2021, 2:55:57 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 58fe85a
- Parents:
- bdfc032 (diff), 44e37ef (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/mutex.cfa
rbdfc032 reef8dfb 30 30 this.lock{}; 31 31 this.blocked_threads{}; 32 this.is_locked = false; 32 33 } 33 34 … … 39 40 lock( lock __cfaabi_dbg_ctx2 ); 40 41 if( is_locked ) { 41 append( blocked_threads, kernelTLS.this_thread ); 42 BlockInternal( &lock ); 42 append( blocked_threads, active_thread() ); 43 unlock( lock ); 44 park(); 43 45 } 44 46 else { … … 62 64 lock( this.lock __cfaabi_dbg_ctx2 ); 63 65 this.is_locked = (this.blocked_threads != 0); 64 WakeThread(66 unpark( 65 67 pop_head( this.blocked_threads ) 66 68 ); … … 84 86 lock( lock __cfaabi_dbg_ctx2 ); 85 87 if( owner == 0p ) { 86 owner = kernelTLS.this_thread;88 owner = active_thread(); 87 89 recursion_count = 1; 88 90 unlock( lock ); 89 91 } 90 else if( owner == kernelTLS.this_thread) {92 else if( owner == active_thread() ) { 91 93 recursion_count++; 92 94 unlock( lock ); 93 95 } 94 96 else { 95 append( blocked_threads, kernelTLS.this_thread ); 96 BlockInternal( &lock ); 97 append( blocked_threads, active_thread() ); 98 unlock( lock ); 99 park(); 97 100 } 98 101 } … … 102 105 lock( lock __cfaabi_dbg_ctx2 ); 103 106 if( owner == 0p ) { 104 owner = kernelTLS.this_thread;107 owner = active_thread(); 105 108 recursion_count = 1; 106 109 ret = true; 107 110 } 108 else if( owner == kernelTLS.this_thread) {111 else if( owner == active_thread() ) { 109 112 recursion_count++; 110 113 ret = true; … … 118 121 recursion_count--; 119 122 if( recursion_count == 0 ) { 120 thread_desc* thrd = pop_head( blocked_threads );123 $thread * thrd = pop_head( blocked_threads ); 121 124 owner = thrd; 122 125 recursion_count = (thrd ? 1 : 0); 123 WakeThread( thrd );126 unpark( thrd ); 124 127 } 125 128 unlock( lock ); … … 138 141 void notify_one(condition_variable & this) with(this) { 139 142 lock( lock __cfaabi_dbg_ctx2 ); 140 WakeThread(143 unpark( 141 144 pop_head( this.blocked_threads ) 142 145 ); … … 147 150 lock( lock __cfaabi_dbg_ctx2 ); 148 151 while(this.blocked_threads) { 149 WakeThread(152 unpark( 150 153 pop_head( this.blocked_threads ) 151 154 ); … … 156 159 void wait(condition_variable & this) { 157 160 lock( this.lock __cfaabi_dbg_ctx2 ); 158 append( this.blocked_threads, kernelTLS.this_thread ); 159 BlockInternal( &this.lock ); 161 append( this.blocked_threads, active_thread() ); 162 unlock( this.lock ); 163 park(); 160 164 } 161 165 … … 163 167 void wait(condition_variable & this, L & l) { 164 168 lock( this.lock __cfaabi_dbg_ctx2 ); 165 append( this.blocked_threads, kernelTLS.this_thread ); 166 void __unlock(void) { 167 unlock(l); 168 unlock(this.lock); 169 } 170 BlockInternal( __unlock ); 169 append( this.blocked_threads, active_thread() ); 170 unlock(l); 171 unlock(this.lock); 172 park(); 171 173 lock(l); 172 174 }
Note:
See TracChangeset
for help on using the changeset viewer.