Changeset 1fbf481 for libcfa


Ignore:
Timestamp:
Jun 26, 2023, 10:20:11 AM (11 months ago)
Author:
caparsons <caparson@…>
Branches:
master
Children:
48ec19a
Parents:
97b47ec
Message:

more actor changes and touchups

File:
1 edited

Legend:

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

    r97b47ec r1fbf481  
    390390struct actor {
    391391    size_t ticket;                                          // executor-queue handle
    392     allocation allocation_;                                         // allocation action
     392    allocation alloc;                                       // 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     allocation_ = Nodelete;
     400    alloc = 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.allocation_ != Nodelete ) {
    410         switch( this.allocation_ ) {
     409    if ( this.alloc != Nodelete ) {
     410        switch( this.alloc ) {
    411411            case Delete: delete( &this ); break;
    412412            case Destroy:
     
    427427
    428428struct message {
    429     allocation allocation_;                     // allocation action
     429    allocation alloc;                   // allocation action
    430430    inline virtual_dtor;
    431431};
    432432
    433433static inline void ?{}( message & this ) {
    434     this.allocation_ = Nodelete;
     434    this.alloc = Nodelete;
    435435}
    436436static inline void ?{}( message & this, allocation alloc ) {
    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" );
     437    memcpy( &this.alloc, &alloc, sizeof(allocation) ); // optimization to elide ctor
     438    CFA_DEBUG( if( this.alloc == Finished ) this.alloc = Nodelete; )
    439439}
    440440static 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        )
    442447}
    443448
    444449static inline void check_message( message & this ) {
    445     switch ( this.allocation_ ) {                                               // analyze message status
    446         case Nodelete: CFA_DEBUG( this.allocation_ = Finished ); break;
     450    switch ( this.alloc ) {                                             // analyze message status
     451        case Nodelete: CFA_DEBUG( this.alloc = Finished ); break;
    447452        case Delete: delete( &this ); break;
    448453        case Destroy: ^?{}( this ); break;
     
    451456}
    452457static inline void set_allocation( message & this, allocation state ) {
    453     this.allocation_ = state;
     458    CFA_DEBUG( if ( state == Nodelete ) state = Finished; )
     459    this.alloc = state;
    454460}
    455461
     
    459465    message * base_msg;
    460466    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
    462468    check_message( *base_msg );
    463469    check_actor( *base_actor );
     
    671677
    672678static inline void stop_actor_system() {
    673     park( ); // will be unparked when actor system is finished
     679    park( ); // unparked when actor system is finished
    674680
    675681    if ( !__actor_executor_passed ) delete( __actor_executor_ );
     
    682688// Default messages to send to any actor to change status
    683689// assigned at creation to __base_msg_finished to avoid unused message warning
    684 message __base_msg_finished @= { .allocation_ : 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 
     690message __base_msg_finished @= { .alloc : Finished };
     691struct delete_message_t { inline message; } delete_msg = __base_msg_finished;
     692struct destroy_msg_t { inline message; } destroy_msg = __base_msg_finished;
     693struct finished_msg_t { inline message; } finished_msg = __base_msg_finished;
     694
     695allocation receive( actor & this, delete_message_t & msg ) { return Delete; }
     696allocation receive( actor & this, destroy_msg_t & msg ) { return Destroy; }
     697allocation receive( actor & this, finished_msg_t & msg ) { return Finished; }
     698
Note: See TracChangeset for help on using the changeset viewer.