Changeset c131a02
- Timestamp:
- Dec 16, 2020, 3:41:51 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- d25b2d6
- Parents:
- e43aa14
- Location:
- libcfa/src/concurrency
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/invoke.h
re43aa14 rc131a02 18 18 #include "bits/locks.hfa" 19 19 #include "kernel/fwd.hfa" 20 #include <stddef.h> 20 21 21 22 #ifdef __cforall … … 189 190 struct __monitor_group_t monitors; 190 191 192 // used to put threads on user data structures 193 struct { 194 struct $thread * next; 195 struct $thread * back; 196 } seqable; 197 191 198 struct { 192 199 struct $thread * next; … … 218 225 } 219 226 227 static inline $thread *& Back( $thread * this ) __attribute__((const)) { 228 return this->seqable.back; 229 } 230 231 static inline $thread *& Next( $thread * this ) __attribute__((const)) { 232 return this->seqable.next; 233 } 234 235 static inline bool listed( $thread * this ) { 236 return this->seqable.next != 0p; 237 } 238 220 239 static inline void ?{}(__monitor_group_t & this) { 221 240 (this.data){0p}; -
libcfa/src/concurrency/locks.cfa
re43aa14 rc131a02 29 29 30 30 void ^?{}( info_thread(L) & this ){ } 31 32 info_thread(L) *& Back( info_thread(L) * this ) { 33 return (info_thread(L) *)Back( (Seqable *)this ); 34 } 35 36 info_thread(L) *& Next( info_thread(L) * this ) { 37 return (info_thread(L) *)Next( (Colable *)this ); 38 } 39 40 bool listed( info_thread(L) * this ) { 41 return Next( (Colable *)this ) != 0p; 42 } 31 43 } 32 44 … … 58 70 abort("A single acquisition lock holder attempted to reacquire the lock resulting in a deadlock."); 59 71 } else if ( owner != 0p && owner != active_thread() ) { 60 a ppend( blocked_threads,active_thread() );72 addTail( blocked_threads, *active_thread() ); 61 73 wait_count++; 62 74 unlock( lock ); … … 96 108 97 109 void pop_and_set_new_owner( blocking_lock & this ) with( this ) { 98 $thread * t = pop_head( blocked_threads );110 $thread * t = &dropHead( blocked_threads ); 99 111 owner = t; 100 112 recursion_count = ( t ? 1 : 0 ); … … 128 140 lock( lock __cfaabi_dbg_ctx2 ); 129 141 if ( owner != 0p ) { 130 a ppend( blocked_threads,t );142 addTail( blocked_threads, *t ); 131 143 wait_count++; 132 144 unlock( lock ); … … 257 269 size_t recursion_count = 0; 258 270 if (i->lock) { 259 i->t->link.next = 1p;260 271 recursion_count = get_recursion_count(*i->lock); 261 272 remove_( *i->lock ); … … 353 364 } 354 365 } 366 367 // const unsigned int num_times = 50000; 368 369 // multiple_acquisition_lock m; 370 // condition_variable( multiple_acquisition_lock ) c_m; 371 372 // single_acquisition_lock s; 373 // condition_variable( single_acquisition_lock ) c_s; 374 375 // owner_lock o; 376 // condition_variable( owner_lock ) c_o; 377 378 // thread T_C_M_WS1 {}; 379 380 // void main( T_C_M_WS1 & this ) { 381 // fprintf(stderr, "start of thd main listed: %d\n", listed(active_thread()) ); 382 // fprintf(stderr, "thread colable next ptr in start of thd main %p\n", Next( (Colable *)active_thread() ) ); 383 // for (unsigned int i = 0; i < num_times; i++) { 384 // lock(m); 385 // if(empty(c_m) && i != num_times - 1) { 386 // wait(c_m,m); 387 // }else{ 388 // notify_one(c_m); 389 // } 390 // unlock(m); 391 // } 392 // } 393 394 // thread T_C_M_WB1 {}; 395 396 // void main( T_C_M_WB1 & this ) { 397 // for (unsigned int i = 0; i < num_times; i++) { 398 // lock(m); 399 // if(counter(c_m) == 3 || i == num_times - 1) { 400 // notify_all(c_m); 401 // }else{ 402 // wait(c_m,m); 403 // } 404 // unlock(m); 405 // } 406 // } 407 408 // thread T_C_S_WS1 {}; 409 410 // void main( T_C_S_WS1 & this ) { 411 // for (unsigned int i = 0; i < num_times; i++) { 412 // lock(s); 413 // if(empty(c_s) && i != num_times - 1) { 414 // wait(c_s,s); 415 // }else{ 416 // notify_one(c_s); 417 // } 418 // unlock(s); 419 // } 420 // } 421 422 // thread T_C_S_WB1 {}; 423 424 // void main( T_C_S_WB1 & this ) { 425 // for (unsigned int i = 0; i < num_times; i++) { 426 // lock(s); 427 // if(counter(c_s) == 3 || i == num_times - 1) { 428 // notify_all(c_s); 429 // }else{ 430 // wait(c_s,s); 431 // } 432 // unlock(s); 433 // } 434 // } 435 436 // thread T_C_O_WS1 {}; 437 438 // void main( T_C_O_WS1 & this ) { 439 // for (unsigned int i = 0; i < num_times; i++) { 440 // lock(o); 441 // if(empty(c_o) && i != num_times - 1) { 442 // wait(c_o,o); 443 // }else{ 444 // notify_one(c_o); 445 // } 446 // unlock(o); 447 // } 448 // } 449 450 // thread T_C_O_WB1 {}; 451 452 // void main( T_C_O_WB1 & this ) { 453 // for (unsigned int i = 0; i < num_times; i++) { 454 // lock(o); 455 // if(counter(c_o) == 3 || i == num_times - 1) { 456 // notify_all(c_o); 457 // }else{ 458 // wait(c_o,o); 459 // } 460 // unlock(o); 461 // } 462 // } 463 464 // thread T_C_M_WS2 {}; 465 466 // void main( T_C_M_WS2 & this ) { 467 // for (unsigned int i = 0; i < num_times; i++) { 468 // lock(m); 469 // lock(m); 470 // lock(m); 471 // if(empty(c_m) && i != num_times - 1) { 472 // wait(c_m,m); 473 // }else{ 474 // notify_one(c_m); 475 // } 476 // unlock(m); 477 // unlock(m); 478 // unlock(m); 479 // } 480 // } 481 482 // thread T_C_O_WS2 {}; 483 484 // void main( T_C_O_WS2 & this ) { 485 // for (unsigned int i = 0; i < num_times; i++) { 486 // lock(o); 487 // lock(o); 488 // lock(o); 489 // if(empty(c_o) && i != num_times - 1) { 490 // wait(c_o,o); 491 // }else{ 492 // notify_one(c_o); 493 // } 494 // unlock(o); 495 // unlock(o); 496 // unlock(o); 497 // } 498 // } 499 500 // thread T_C_NLW {}; 501 502 // void main( T_C_NLW & this ) { 503 // for (unsigned int i = 0; i < num_times; i++) { 504 // wait(c_o); 505 // } 506 // } 507 508 // thread T_C_NLS {}; 509 510 // void main( T_C_NLS & this ) { 511 // for (unsigned int i = 0; i < num_times; i++) { 512 // while (empty(c_o)) { } 513 // notify_one(c_o); 514 // } 515 // } 516 517 // thread T_C_S_WNF {}; 518 519 // void main( T_C_S_WNF & this ) { 520 // for (unsigned int i = 0; i < num_times; i++) { 521 // lock(s); 522 // if(empty(c_s) && i != num_times - 1) { 523 // wait(c_s, s, 10); 524 // }else{ 525 // if(!empty(c_s)) assert(front(c_s) == 10); 526 // notify_one(c_s); 527 // } 528 // unlock(s); 529 // } 530 // } 531 532 // bool done = false; 533 534 // thread T_C_NLWD {}; 535 536 // void main( T_C_NLWD & this ) { 537 // done = false; 538 // for (unsigned int i = 0; i < num_times; i++) { 539 // wait(c_s, 1`ns); 540 // } 541 // done = true; 542 // } 543 544 // thread T_C_WDS {}; 545 546 // void main( T_C_WDS & this ) { 547 // for (unsigned int i = 0; i < num_times; i++) { 548 // while (empty(c_s) && !done) { } 549 // notify_one(c_s); 550 // sleep(1`ns); 551 // if(done) break; 552 // } 553 // } 554 555 // thread T_C_LWD {}; 556 557 // void main( T_C_LWD & this ) { 558 // done = false; 559 // for (unsigned int i = 0; i < num_times; i++) { 560 // if (i % 500 == 0) printf("!! %d\n", i); 561 // lock(s); 562 // wait(c_s, s, 1`ns); 563 // unlock(s); 564 // } 565 // done = true; 566 // } 567 568 // int main() { 569 // processor p[2]; 570 // printf("Start Test 1: multi acquisition lock and condition variable single wait/notify\n"); 571 // { 572 // T_C_M_WS1 t1; 573 // } 574 // printf("Done Test 1\n"); 575 576 // printf("Start Test 2: multi acquisition lock and condition variable 3 wait/notify all\n"); 577 // { 578 // T_C_M_WB1 t1[4]; 579 // } 580 // printf("Done Test 2\n"); 581 582 // printf("Start Test 3: single acquisition lock and condition variable single wait/notify\n"); 583 // { 584 // T_C_S_WS1 t1[2]; 585 // } 586 // printf("Done Test 3\n"); 587 588 // printf("Start Test 4: single acquisition lock and condition variable 3 wait/notify all\n"); 589 // { 590 // T_C_S_WB1 t1[4]; 591 // } 592 // printf("Done Test 4\n"); 593 594 // printf("Start Test 5: owner lock and condition variable single wait/notify\n"); 595 // { 596 // T_C_O_WS1 t1[2]; 597 // } 598 // printf("Done Test 5\n"); 599 600 // printf("Start Test 6: owner lock and condition variable 3 wait/notify all\n"); 601 // { 602 // T_C_O_WB1 t1[4]; 603 // } 604 // printf("Done Test 6\n"); 605 606 // printf("Start Test 7: multi acquisiton lock and condition variable multiple acquire and wait/notify\n"); 607 // { 608 // T_C_M_WS2 t1[2]; 609 // } 610 // printf("Done Test 7\n"); 611 612 // printf("Start Test 8: owner lock and condition variable multiple acquire and wait/notify\n"); 613 // { 614 // T_C_O_WS2 t1[2]; 615 // } 616 // printf("Done Test 8\n"); 617 618 // printf("Start Test 9: no lock condition variable wait/notify\n"); 619 // { 620 // T_C_NLW t1; 621 // T_C_NLS t2; 622 // } 623 // printf("Done Test 9\n"); 624 625 // printf("Start Test 10: locked condition variable wait/notify with front()\n"); 626 // { 627 // T_C_S_WNF t1[2]; 628 // } 629 // printf("Done Test 10\n"); 630 631 // printf("Start Test 11: unlocked condition variable delay wait\n"); 632 // { 633 // T_C_NLWD t1; 634 // T_C_WDS t2; 635 // } 636 // printf("Done Test 11\n"); 637 638 // // printf("Start Test 12: locked condition variable delay wait\n"); 639 // // { 640 // // T_C_LWD t1; 641 // // T_C_WDS t2; 642 // // } 643 // // printf("Done Test 12\n"); 644 // } -
libcfa/src/concurrency/locks.hfa
re43aa14 rc131a02 43 43 void ?{}( info_thread(L) & this, $thread * t, uintptr_t info ); 44 44 void ^?{}( info_thread(L) & this ); 45 46 info_thread(L) *& Back( info_thread(L) * this ); 47 info_thread(L) *& Next( info_thread(L) * this ); 48 bool listed( info_thread(L) * this ); 45 49 } 46 50 … … 64 68 65 69 // List of blocked threads 66 __queue_t( $thread ) blocked_threads;70 Sequence( $thread ) blocked_threads; 67 71 68 72 // Count of current blocked threads -
libcfa/src/concurrency/thread.cfa
re43aa14 rc131a02 43 43 canary = 0x0D15EA5E0D15EA5Ep; 44 44 #endif 45 46 seqable.next = 0p; 47 seqable.back = 0p; 45 48 46 49 node.next = 0p;
Note: See TracChangeset
for help on using the changeset viewer.