Changeset 39fc03e
- Timestamp:
- Jul 24, 2020, 3:42:32 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 7458fea
- Parents:
- 320ec6fc
- Location:
- libcfa/src/concurrency
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel.cfa
r320ec6fc r39fc03e 324 324 threads{ __get }; 325 325 326 doregister(this); 327 328 // Lock the RWlock so no-one pushes/pops while we are changing the queue 329 uint_fast32_t last_size = ready_mutate_lock(); 330 331 // Adjust the ready queue size 332 ready_queue_grow( &this, 0 ); 333 334 // Unlock the RWlock 335 ready_mutate_unlock( last_size ); 336 337 326 338 __kernel_io_startup( this, io_flags, &this == mainCluster ); 327 328 doregister(this);329 339 } 330 340 331 341 void ^?{}(cluster & this) { 332 342 __kernel_io_shutdown( this, &this == mainCluster ); 343 344 // Lock the RWlock so no-one pushes/pops while we are changing the queue 345 uint_fast32_t last_size = ready_mutate_lock(); 346 347 // Adjust the ready queue size 348 ready_queue_shrink( &this, 0 ); 349 350 // Unlock the RWlock 351 ready_mutate_unlock( last_size ); 333 352 334 353 #if !defined(__CFA_NO_STATISTICS__) -
libcfa/src/concurrency/ready_queue.cfa
r320ec6fc r39fc03e 191 191 192 192 void ^?{}(__ready_queue_t & this) with (this) { 193 verify( 0== lanes.count );193 verify( 1 == lanes.count ); 194 194 verify( !query( snzi ) ); 195 195 free(lanes.data); … … 484 484 } 485 485 486 #warning remove when alloc is fixed487 forall( dtype T | sized(T) )488 static inline T * correct_alloc( T ptr[], size_t dim ) {489 if( dim == 0 ) {490 free(ptr);491 return 0p;492 }493 T * temp = alloc( dim );494 if(ptr) {495 memcpy( temp, ptr, dim * sizeof(T));496 free(ptr);497 }498 return temp;499 }500 501 486 // Grow the ready queue 502 487 void ready_queue_grow (struct cluster * cltr, int target) { … … 511 496 ^(snzi){}; 512 497 513 size_t ncount = lanes.count; 514 515 // increase count 516 ncount += 4; 517 /* paranoid */ verify( ncount == target * 4 || target < 2 ); 498 // Find new count 499 // Make sure we always have atleast 1 list 500 size_t ncount = target >= 2 ? target * 4: 1; 518 501 519 502 // Allocate new array (uses realloc and memcpies the data) 520 lanes.data = correct_alloc(lanes.data, ncount);503 lanes.data = alloc(lanes.data, ncount); 521 504 522 505 // Fix the moved data … … 561 544 ^(snzi){}; 562 545 546 // Remember old count 563 547 size_t ocount = lanes.count; 564 // Check that we have some space left 565 if(ocount < 4) abort("Program attempted to destroy more Ready Queues than were created"); 566 567 // reduce the actual count so push doesn't use the old queues 568 lanes.count -= 4; 569 /* paranoid */ verify( ocount > lanes.count ); 548 549 // Find new count 550 // Make sure we always have atleast 1 list 551 lanes.count = target >= 2 ? target * 4: 1; 552 /* paranoid */ verify( ocount >= lanes.count ); 570 553 /* paranoid */ verify( lanes.count == target * 4 || target < 2 ); 571 554 … … 606 589 607 590 // Allocate new array (uses realloc and memcpies the data) 608 lanes.data = correct_alloc(lanes.data, lanes.count);591 lanes.data = alloc(lanes.data, lanes.count); 609 592 610 593 // Fix the moved data
Note: See TracChangeset
for help on using the changeset viewer.