Changes in / [13099105:935315d]
- Location:
- src
- Files:
-
- 2 deleted
- 4 edited
-
libcfa/concurrency/monitor (modified) (1 diff)
-
libcfa/concurrency/monitor.c (modified) (10 diffs)
-
libcfa/concurrency/thread (modified) (1 diff)
-
libcfa/concurrency/thread.c (modified) (1 diff)
-
tests/.expect/concurrent/sched-int-block.txt (deleted)
-
tests/sched-int-block.c (deleted)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/monitor
r13099105 r935315d 87 87 void wait( condition * this ); 88 88 void signal( condition * this ); 89 void signal_block( condition * this );90 89 #endif //MONITOR_H -
src/libcfa/concurrency/monitor.c
r13099105 r935315d 62 62 //Some one else has the monitor, wait in line for it 63 63 append( &this->entry_queue, thrd ); 64 LIB_DEBUG_PRINT_SAFE("%p Blocking on entry\n", thrd);65 64 ScheduleInternal( &this->lock ); 66 65 … … 98 97 unlock( &this->lock ); 99 98 100 LIB_DEBUG_PRINT_SAFE("Next owner is %p\n", new_owner);101 102 99 //We need to wake-up the thread 103 100 ScheduleThread( new_owner ); … … 152 149 assertf( this->monitors != NULL, "Waiting with no monitors (%p)", this->monitors ); 153 150 assertf( this->monitor_count != 0, "Waiting with 0 monitors (%i)", this->monitor_count ); 154 assertf( this->monitor_count < 32u, "Excessive monitor count (%i)", this->monitor_count );155 151 156 152 unsigned short count = this->monitor_count; … … 188 184 } 189 185 186 debug_break(); 187 190 188 for( int i = 0; i < count; i++) { 191 189 thread_desc * new_owner = next_thread( this->monitors[i] ); … … 193 191 } 194 192 193 debug_break(); 194 195 195 LIB_DEBUG_PRINT_SAFE("Will unblock: "); 196 196 for(int i = 0; i < thread_count; i++) { … … 202 202 ScheduleInternal( locks, count, threads, thread_count ); 203 203 204 debug_break(); 204 205 205 //WE WOKE UP 206 206 … … 224 224 unsigned short count = this->monitor_count; 225 225 226 //Some more checking in debug227 226 LIB_DEBUG_DO( 228 227 thread_desc * this_thrd = this_thread(); … … 238 237 ); 239 238 240 //Lock all the monitors241 239 lock_all( this->monitors, NULL, count ); 242 240 LIB_DEBUG_PRINT_SAFE("Signalling"); 243 241 244 //Pop the head of the waiting queue245 242 __condition_node_t * node = pop_head( &this->blocked ); 246 247 //Add the thread to the proper AS stack248 243 for(int i = 0; i < count; i++) { 249 244 __condition_criterion_t * crit = &node->criteria[i]; … … 255 250 LIB_DEBUG_PRINT_SAFE("\n"); 256 251 257 //Release258 252 unlock_all( this->monitors, count ); 259 }260 261 void signal_block( condition * this ) {262 if( !this->blocked.head ) {263 LIB_DEBUG_PRINT_SAFE("Nothing to signal\n");264 return;265 }266 267 //Check that everything is as expected268 assertf( this->monitors != NULL, "Waiting with no monitors (%p)", this->monitors );269 assertf( this->monitor_count != 0, "Waiting with 0 monitors (%i)", this->monitor_count );270 271 unsigned short count = this->monitor_count;272 unsigned int recursions[ count ]; //Save the current recursion levels to restore them later273 spinlock * locks [ count ]; //We need to pass-in an array of locks to ScheduleInternal274 275 lock_all( this->monitors, locks, count );276 277 //create creteria278 __condition_node_t waiter;279 waiter.waiting_thread = this_thread();280 waiter.count = count;281 waiter.next = NULL;282 283 __condition_criterion_t criteria[count];284 for(int i = 0; i < count; i++) {285 LIB_DEBUG_PRINT_SAFE( "Criterion %p\n", &criteria[i] );286 criteria[i].ready = false;287 criteria[i].owner = &waiter;288 criteria[i].next = NULL;289 criteria[i].target = this->monitors[i];290 push( &criteria[i].target->signal_stack, &criteria[i] );291 }292 293 waiter.criteria = criteria;294 295 //save contexts296 save_recursion( this->monitors, recursions, count );297 298 //Find the thread to run299 thread_desc * signallee = pop_head( &this->blocked )->waiting_thread;300 for(int i = 0; i < count; i++) {301 set_owner( this->monitors[i], signallee );302 }303 304 LIB_DEBUG_PRINT_SAFE( "Waiting on signal block\n" );305 debug_break();306 307 //Everything is ready to go to sleep308 ScheduleInternal( locks, count, &signallee, 1 );309 310 debug_break();311 LIB_DEBUG_PRINT_SAFE( "Back from signal block\n" );312 313 //We are back, restore the owners and recursions314 lock_all( locks, count );315 restore_recursion( this->monitors, recursions, count );316 unlock_all( locks, count );317 253 } 318 254 … … 399 335 400 336 for( int i = 0; i < count; i++ ) { 401 402 337 LIB_DEBUG_PRINT_SAFE( "Checking %p for %p\n", &criteria[i], target ); 403 338 if( &criteria[i] == target ) { -
src/libcfa/concurrency/thread
r13099105 r935315d 82 82 83 83 void yield(); 84 void yield( unsigned times );85 84 86 85 #endif //THREADS_H -
src/libcfa/concurrency/thread.c
r13099105 r935315d 87 87 } 88 88 89 void yield( unsigned times ) {90 for( unsigned i = 0; i < times; i++ ) {91 yield();92 }93 }94 95 89 void ThreadCtxSwitch(coroutine_desc* src, coroutine_desc* dst) { 96 90 // set state of current coroutine to inactive
Note:
See TracChangeset
for help on using the changeset viewer.