- File:
-
- 1 edited
-
libcfa/src/concurrency/locks.cfa (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/locks.cfa
r305aaef rc18bf9e 24 24 #include <stdlib.hfa> 25 25 26 #pragma GCC visibility push(default) 27 26 28 //----------------------------------------------------------------------------- 27 29 // info_thread … … 116 118 } 117 119 118 void pop_and_set_new_owner( blocking_lock & this ) with( this ) {120 static void pop_and_set_new_owner( blocking_lock & this ) with( this ) { 119 121 thread$ * t = &try_pop_front( blocked_threads ); 120 122 owner = t; … … 174 176 recursion_count = recursion; 175 177 } 176 177 //-----------------------------------------------------------------------------178 // simple_owner_lock179 180 static inline void lock(simple_owner_lock & this) with(this) {181 if (owner == active_thread()) {182 recursion_count++;183 return;184 }185 lock( lock __cfaabi_dbg_ctx2 );186 187 if (owner != 0p) {188 insert_last( blocked_threads, *active_thread() );189 unlock( lock );190 park( );191 return;192 }193 owner = active_thread();194 recursion_count = 1;195 unlock( lock );196 }197 198 void pop_and_set_new_owner( simple_owner_lock & this ) with( this ) {199 thread$ * t = &try_pop_front( blocked_threads );200 owner = t;201 recursion_count = ( t ? 1 : 0 );202 unpark( t );203 }204 205 static inline void unlock(simple_owner_lock & this) with(this) {206 lock( lock __cfaabi_dbg_ctx2 );207 /* paranoid */ verifyf( owner != 0p, "Attempt to release lock %p that isn't held", &this );208 /* paranoid */ verifyf( owner == active_thread(), "Thread %p other than the owner %p attempted to release owner lock %p", owner, active_thread(), &this );209 // if recursion count is zero release lock and set new owner if one is waiting210 recursion_count--;211 if ( recursion_count == 0 ) {212 pop_and_set_new_owner( this );213 }214 unlock( lock );215 }216 217 static inline void on_notify(simple_owner_lock & this, struct thread$ * t ) with(this) {218 lock( lock __cfaabi_dbg_ctx2 );219 // lock held220 if ( owner != 0p ) {221 insert_last( blocked_threads, *t );222 unlock( lock );223 }224 // lock not held225 else {226 owner = t;227 recursion_count = 1;228 unpark( t );229 unlock( lock );230 }231 }232 233 static inline size_t on_wait(simple_owner_lock & this) with(this) {234 lock( lock __cfaabi_dbg_ctx2 );235 /* paranoid */ verifyf( owner != 0p, "Attempt to release lock %p that isn't held", &this );236 /* paranoid */ verifyf( owner == active_thread(), "Thread %p other than the owner %p attempted to release owner lock %p", owner, active_thread(), &this );237 238 size_t ret = recursion_count;239 240 pop_and_set_new_owner( this );241 242 unlock( lock );243 return ret;244 }245 246 static inline void on_wakeup(simple_owner_lock & this, size_t recursion ) with(this) { recursion_count = recursion; }247 248 178 249 179 //----------------------------------------------------------------------------- … … 264 194 void ^?{}( alarm_node_wrap(L) & this ) { } 265 195 266 void timeout_handler ( alarm_node_wrap(L) & this ) with( this ) {196 static void timeout_handler ( alarm_node_wrap(L) & this ) with( this ) { 267 197 // This condition_variable member is called from the kernel, and therefore, cannot block, but it can spin. 268 198 lock( cond->lock __cfaabi_dbg_ctx2 ); … … 288 218 289 219 // this casts the alarm node to our wrapped type since we used type erasure 290 void alarm_node_wrap_cast( alarm_node_t & a ) { timeout_handler( (alarm_node_wrap(L) &)a ); }220 static void alarm_node_wrap_cast( alarm_node_t & a ) { timeout_handler( (alarm_node_wrap(L) &)a ); } 291 221 } 292 222 … … 305 235 void ^?{}( condition_variable(L) & this ){ } 306 236 307 void process_popped( condition_variable(L) & this, info_thread(L) & popped ) with( this ) {237 static void process_popped( condition_variable(L) & this, info_thread(L) & popped ) with( this ) { 308 238 if(&popped != 0p) { 309 239 popped.signalled = true; … … 350 280 int counter( condition_variable(L) & this ) with(this) { return count; } 351 281 352 s ize_t queue_and_get_recursion( condition_variable(L) & this, info_thread(L) * i ) with(this) {282 static size_t queue_and_get_recursion( condition_variable(L) & this, info_thread(L) * i ) with(this) { 353 283 // add info_thread to waiting queue 354 284 insert_last( blocked_threads, *i ); … … 363 293 364 294 // helper for wait()'s' with no timeout 365 void queue_info_thread( condition_variable(L) & this, info_thread(L) & i ) with(this) {295 static void queue_info_thread( condition_variable(L) & this, info_thread(L) & i ) with(this) { 366 296 lock( lock __cfaabi_dbg_ctx2 ); 367 297 size_t recursion_count = queue_and_get_recursion(this, &i); … … 380 310 381 311 // helper for wait()'s' with a timeout 382 void queue_info_thread_timeout( condition_variable(L) & this, info_thread(L) & info, Duration t, Alarm_Callback callback ) with(this) {312 static void queue_info_thread_timeout( condition_variable(L) & this, info_thread(L) & info, Duration t, Alarm_Callback callback ) with(this) { 383 313 lock( lock __cfaabi_dbg_ctx2 ); 384 314 size_t recursion_count = queue_and_get_recursion(this, &info); … … 415 345 // fast_cond_var 416 346 void ?{}( fast_cond_var(L) & this ){ 417 this.blocked_threads{}; 347 this.blocked_threads{}; 418 348 #ifdef __CFA_DEBUG__ 419 349 this.lock_used = 0p;
Note:
See TracChangeset
for help on using the changeset viewer.