- File:
-
- 1 edited
-
libcfa/src/concurrency/actor.hfa (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/actor.hfa
r1fbf481 rb065dbb 390 390 struct actor { 391 391 size_t ticket; // executor-queue handle 392 allocation alloc ; // allocation action392 allocation allocation_; // 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 = Nodelete;400 allocation_ = 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 != Nodelete ) {410 switch( this.alloc ) {409 if ( this.allocation_ != Nodelete ) { 410 switch( this.allocation_ ) { 411 411 case Delete: delete( &this ); break; 412 412 case Destroy: … … 427 427 428 428 struct message { 429 allocation alloc ; // allocation action429 allocation allocation_; // allocation action 430 430 inline virtual_dtor; 431 431 }; 432 432 433 433 static inline void ?{}( message & this ) { 434 this.alloc = Nodelete;434 this.allocation_ = Nodelete; 435 435 } 436 436 static inline void ?{}( message & this, allocation alloc ) { 437 memcpy( &this.alloc , &alloc, sizeof(allocation) ); // optimization to elide ctor438 CFA_DEBUG( if( this.alloc == Finished ) this.alloc = Nodelete; )437 memcpy( &this.allocation_, &alloc, sizeof(allocation) ); // optimization to elide ctor 438 DEBUG_ABORT( this.allocation_ == Finished, "The Finished allocation status is not supported for message types.\n" ); 439 439 } 440 440 static inline void ^?{}( message & this ) with(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 ) 441 CFA_DEBUG( if ( allocation_ == Nodelete ) printf("A message at location %p was allocated but never sent.\n", &this); ) 447 442 } 448 443 449 444 static inline void check_message( message & this ) { 450 switch ( this.alloc ) { // analyze message status451 case Nodelete: CFA_DEBUG( this.alloc = Finished ); break;445 switch ( this.allocation_ ) { // analyze message status 446 case Nodelete: CFA_DEBUG( this.allocation_ = Finished ); break; 452 447 case Delete: delete( &this ); break; 453 448 case Destroy: ^?{}( this ); break; … … 456 451 } 457 452 static inline void set_allocation( message & this, allocation state ) { 458 CFA_DEBUG( if ( state == Nodelete ) state = Finished; ) 459 this.alloc = state; 453 this.allocation_ = state; 460 454 } 461 455 … … 465 459 message * base_msg; 466 460 allocation temp = this.fn( *this.receiver, *this.msg, &base_actor, &base_msg ); 467 memcpy( &base_actor->alloc, &temp, sizeof(allocation) ); // optimization to elide ctor461 base_actor->allocation_ = temp; 468 462 check_message( *base_msg ); 469 463 check_actor( *base_actor ); … … 630 624 empty_count = 0; // we found work so reset empty counter 631 625 #endif 632 633 CHECK_TERMINATION;634 626 635 627 // potentially reclaim some of the current queue's vector space if it is unused … … 677 669 678 670 static inline void stop_actor_system() { 679 park( ); // unparked when actor system is finished671 park( ); // will be unparked when actor system is finished 680 672 681 673 if ( !__actor_executor_passed ) delete( __actor_executor_ ); … … 688 680 // Default messages to send to any actor to change status 689 681 // assigned at creation to __base_msg_finished to avoid unused message warning 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 682 message __base_msg_finished @= { .allocation_ : Finished }; 683 struct __delete_msg_t { inline message; } delete_msg = __base_msg_finished; 684 struct __destroy_msg_t { inline message; } destroy_msg = __base_msg_finished; 685 struct __finished_msg_t { inline message; } finished_msg = __base_msg_finished; 686 687 allocation receive( actor & this, __delete_msg_t & msg ) { return Delete; } 688 allocation receive( actor & this, __destroy_msg_t & msg ) { return Destroy; } 689 allocation receive( actor & this, __finished_msg_t & msg ) { return Finished; } 690
Note:
See TracChangeset
for help on using the changeset viewer.