Changeset 1fbf481 for libcfa/src/concurrency
- Timestamp:
- Jun 26, 2023, 10:20:11 AM (15 months ago)
- Branches:
- master
- Children:
- 48ec19a
- Parents:
- 97b47ec
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/actor.hfa
r97b47ec r1fbf481 390 390 struct actor { 391 391 size_t ticket; // executor-queue handle 392 allocation alloc ation_; // allocation action392 allocation alloc; // allocation action 393 393 inline virtual_dtor; 394 394 }; … … 398 398 // member must be called to end it 399 399 DEBUG_ABORT( __actor_executor_ == 0p, "Creating actor before calling start_actor_system() can cause undefined behaviour.\n" ); 400 alloc ation_= Nodelete;400 alloc = Nodelete; 401 401 ticket = __get_next_ticket( *__actor_executor_ ); 402 402 __atomic_fetch_add( &__num_actors_, 1, __ATOMIC_RELAXED ); … … 407 407 408 408 static inline void check_actor( actor & this ) { 409 if ( this.alloc ation_!= Nodelete ) {410 switch( this.alloc ation_) {409 if ( this.alloc != Nodelete ) { 410 switch( this.alloc ) { 411 411 case Delete: delete( &this ); break; 412 412 case Destroy: … … 427 427 428 428 struct message { 429 allocation alloc ation_; // allocation action429 allocation alloc; // allocation action 430 430 inline virtual_dtor; 431 431 }; 432 432 433 433 static inline void ?{}( message & this ) { 434 this.alloc ation_= Nodelete;434 this.alloc = Nodelete; 435 435 } 436 436 static inline void ?{}( message & this, allocation alloc ) { 437 memcpy( &this.alloc ation_, &alloc, sizeof(allocation) ); // optimization to elide ctor438 DEBUG_ABORT( this.allocation_ == Finished, "The Finished allocation status is not supported for message types.\n" );437 memcpy( &this.alloc, &alloc, sizeof(allocation) ); // optimization to elide ctor 438 CFA_DEBUG( if( this.alloc == Finished ) this.alloc = Nodelete; ) 439 439 } 440 440 static inline void ^?{}( message & this ) with(this) { 441 CFA_DEBUG( if ( allocation_ == Nodelete ) printf("A message at location %p was allocated but never sent.\n", &this); ) 441 CFA_DEBUG( 442 if ( alloc == Nodelete ) { 443 printf( "CFA warning (UNIX pid:%ld) : program terminating with message %p allocated but never sent.\n", 444 (long int)getpid(), &this ); 445 } 446 ) 442 447 } 443 448 444 449 static inline void check_message( message & this ) { 445 switch ( this.alloc ation_) { // analyze message status446 case Nodelete: CFA_DEBUG( this.alloc ation_= Finished ); break;450 switch ( this.alloc ) { // analyze message status 451 case Nodelete: CFA_DEBUG( this.alloc = Finished ); break; 447 452 case Delete: delete( &this ); break; 448 453 case Destroy: ^?{}( this ); break; … … 451 456 } 452 457 static inline void set_allocation( message & this, allocation state ) { 453 this.allocation_ = state; 458 CFA_DEBUG( if ( state == Nodelete ) state = Finished; ) 459 this.alloc = state; 454 460 } 455 461 … … 459 465 message * base_msg; 460 466 allocation temp = this.fn( *this.receiver, *this.msg, &base_actor, &base_msg ); 461 base_actor->allocation_ = temp;467 memcpy( &base_actor->alloc, &temp, sizeof(allocation) ); // optimization to elide ctor 462 468 check_message( *base_msg ); 463 469 check_actor( *base_actor ); … … 671 677 672 678 static inline void stop_actor_system() { 673 park( ); // will beunparked when actor system is finished679 park( ); // unparked when actor system is finished 674 680 675 681 if ( !__actor_executor_passed ) delete( __actor_executor_ ); … … 682 688 // Default messages to send to any actor to change status 683 689 // assigned at creation to __base_msg_finished to avoid unused message warning 684 message __base_msg_finished @= { .alloc ation_: Finished };685 struct __delete_msg_t { inline message; } delete_msg = __base_msg_finished;686 struct __destroy_msg_t { inline message; } destroy_msg = __base_msg_finished;687 struct __finished_msg_t { inline message; } finished_msg = __base_msg_finished;688 689 allocation receive( actor & this, __delete_msg_t & msg ) { return Delete; }690 allocation receive( actor & this, __destroy_msg_t & msg ) { return Destroy; }691 allocation receive( actor & this, __finished_msg_t & msg ) { return Finished; }692 690 message __base_msg_finished @= { .alloc : Finished }; 691 struct delete_message_t { inline message; } delete_msg = __base_msg_finished; 692 struct destroy_msg_t { inline message; } destroy_msg = __base_msg_finished; 693 struct finished_msg_t { inline message; } finished_msg = __base_msg_finished; 694 695 allocation receive( actor & this, delete_message_t & msg ) { return Delete; } 696 allocation receive( actor & this, destroy_msg_t & msg ) { return Destroy; } 697 allocation receive( actor & this, finished_msg_t & msg ) { return Finished; } 698
Note: See TracChangeset
for help on using the changeset viewer.