- File:
-
- 1 edited
-
libcfa/src/concurrency/monitor.cfa (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/monitor.cfa
raf67ee1 re84ab3d 367 367 368 368 // __cfaabi_dbg_print_safe( "MGUARD : entered\n" ); 369 }370 371 void ?{}( monitor_guard_t & this, monitor$ * m [], __lock_size_t count ) {372 this{ m, count, 0p };373 369 } 374 370 … … 990 986 } 991 987 992 //-----------------------------------------------------------------------------993 // Enter routine for mutex stmt994 // Can't be accepted since a mutex stmt is effectively an anonymous routine995 // Thus we do not need a monitor group996 void lock( monitor$ * this ) {997 thread$ * thrd = active_thread();998 999 // Lock the monitor spinlock1000 lock( this->lock __cfaabi_dbg_ctx2 );1001 1002 __cfaabi_dbg_print_safe( "Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner);1003 1004 if( unlikely(0 != (0x1 & (uintptr_t)this->owner)) ) {1005 abort( "Attempt by thread \"%.256s\" (%p) to access joined monitor %p.", thrd->self_cor.name, thrd, this );1006 }1007 else if( !this->owner ) {1008 // No one has the monitor, just take it1009 __set_owner( this, thrd );1010 1011 __cfaabi_dbg_print_safe( "Kernel : mon is free \n" );1012 }1013 else if( this->owner == thrd) {1014 // We already have the monitor, just note how many times we took it1015 this->recursion += 1;1016 1017 __cfaabi_dbg_print_safe( "Kernel : mon already owned \n" );1018 }1019 else {1020 __cfaabi_dbg_print_safe( "Kernel : blocking \n" );1021 1022 // Some one else has the monitor, wait in line for it1023 /* paranoid */ verify( thrd->link.next == 0p );1024 append( this->entry_queue, thrd );1025 /* paranoid */ verify( thrd->link.next == 1p );1026 1027 unlock( this->lock );1028 park();1029 1030 __cfaabi_dbg_print_safe( "Kernel : %10p Entered mon %p\n", thrd, this);1031 1032 /* paranoid */ verifyf( active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this );1033 return;1034 }1035 1036 __cfaabi_dbg_print_safe( "Kernel : %10p Entered mon %p\n", thrd, this);1037 1038 /* paranoid */ verifyf( active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this );1039 /* paranoid */ verify( this->lock.lock );1040 1041 // Release the lock and leave1042 unlock( this->lock );1043 return;1044 }1045 1046 // Leave routine for mutex stmt1047 // Is just a wrapper around __leave for the is_lock trait to see1048 void unlock( monitor$ * this ) { __leave( this ); }1049 1050 988 // Local Variables: // 1051 989 // mode: c //
Note:
See TracChangeset
for help on using the changeset viewer.