Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/actor.hfa

    r1fbf481 rb065dbb  
    390390struct actor {
    391391    size_t ticket;                                          // executor-queue handle
    392     allocation alloc;                                       // allocation action
     392    allocation allocation_;                                         // allocation action
    393393    inline virtual_dtor;
    394394};
     
    398398    // member must be called to end it
    399399    DEBUG_ABORT( __actor_executor_ == 0p, "Creating actor before calling start_actor_system() can cause undefined behaviour.\n" );
    400     alloc = Nodelete;
     400    allocation_ = Nodelete;
    401401    ticket = __get_next_ticket( *__actor_executor_ );
    402402    __atomic_fetch_add( &__num_actors_, 1, __ATOMIC_RELAXED );
     
    407407
    408408static inline void check_actor( actor & this ) {
    409     if ( this.alloc != Nodelete ) {
    410         switch( this.alloc ) {
     409    if ( this.allocation_ != Nodelete ) {
     410        switch( this.allocation_ ) {
    411411            case Delete: delete( &this ); break;
    412412            case Destroy:
     
    427427
    428428struct message {
    429     allocation alloc;                   // allocation action
     429    allocation allocation_;                     // allocation action
    430430    inline virtual_dtor;
    431431};
    432432
    433433static inline void ?{}( message & this ) {
    434     this.alloc = Nodelete;
     434    this.allocation_ = Nodelete;
    435435}
    436436static inline void ?{}( message & this, allocation alloc ) {
    437     memcpy( &this.alloc, &alloc, sizeof(allocation) ); // optimization to elide ctor
    438     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" );
    439439}
    440440static 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); )
    447442}
    448443
    449444static inline void check_message( message & this ) {
    450     switch ( this.alloc ) {                                             // analyze message status
    451         case Nodelete: CFA_DEBUG( this.alloc = Finished ); break;
     445    switch ( this.allocation_ ) {                                               // analyze message status
     446        case Nodelete: CFA_DEBUG( this.allocation_ = Finished ); break;
    452447        case Delete: delete( &this ); break;
    453448        case Destroy: ^?{}( this ); break;
     
    456451}
    457452static inline void set_allocation( message & this, allocation state ) {
    458     CFA_DEBUG( if ( state == Nodelete ) state = Finished; )
    459     this.alloc = state;
     453    this.allocation_ = state;
    460454}
    461455
     
    465459    message * base_msg;
    466460    allocation temp = this.fn( *this.receiver, *this.msg, &base_actor, &base_msg );
    467     memcpy( &base_actor->alloc, &temp, sizeof(allocation) ); // optimization to elide ctor
     461    base_actor->allocation_ = temp;
    468462    check_message( *base_msg );
    469463    check_actor( *base_actor );
     
    630624        empty_count = 0; // we found work so reset empty counter
    631625        #endif
    632 
    633         CHECK_TERMINATION;
    634626       
    635627        // potentially reclaim some of the current queue's vector space if it is unused
     
    677669
    678670static inline void stop_actor_system() {
    679     park( ); // unparked when actor system is finished
     671    park( ); // will be unparked when actor system is finished
    680672
    681673    if ( !__actor_executor_passed ) delete( __actor_executor_ );
     
    688680// Default messages to send to any actor to change status
    689681// 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 
     682message __base_msg_finished @= { .allocation_ : Finished };
     683struct __delete_msg_t { inline message; } delete_msg = __base_msg_finished;
     684struct __destroy_msg_t { inline message; } destroy_msg = __base_msg_finished;
     685struct __finished_msg_t { inline message; } finished_msg = __base_msg_finished;
     686
     687allocation receive( actor & this, __delete_msg_t & msg ) { return Delete; }
     688allocation receive( actor & this, __destroy_msg_t & msg ) { return Destroy; }
     689allocation receive( actor & this, __finished_msg_t & msg ) { return Finished; }
     690
Note: See TracChangeset for help on using the changeset viewer.