Ignore:
Timestamp:
Jun 4, 2023, 8:38:45 AM (18 months ago)
Author:
caparsons <caparson@…>
Branches:
ast-experimental, master
Children:
c880a7b
Parents:
46e6e47
Message:

refactored allocation enum to match naming style and refactored some verifyf's to be aborts

File:
1 edited

Legend:

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

    r46e6e47 r0794365  
    1313#endif // CFA_DEBUG
    1414
     15#define DEBUG_ABORT( cond, string ) CFA_DEBUG( if ( cond ) abort( string ) )
     16
    1517// Define the default number of processors created in the executor. Must be greater than 0.
    1618#define __DEFAULT_EXECUTOR_PROCESSORS__ 2
     
    4244struct executor;
    4345
    44 enum Allocation { Nodelete, Delete, Destroy, Finished }; // allocation status
    45 
    46 typedef Allocation (*__receive_fn)(actor &, message &);
     46enum allocation { Nodelete, Delete, Destroy, Finished }; // allocation status
     47
     48typedef allocation (*__receive_fn)(actor &, message &);
    4749struct request {
    4850    actor * receiver;
     
    393395struct actor {
    394396    size_t ticket;                                          // executor-queue handle
    395     Allocation allocation_;                                         // allocation action
     397    allocation allocation_;                                         // allocation action
    396398    inline virtual_dtor;
    397399};
     
    400402    // Once an actor is allocated it must be sent a message or the actor system cannot stop. Hence, its receive
    401403    // member must be called to end it
    402     verifyf( __actor_executor_, "Creating actor before calling start_actor_system() can cause undefined behaviour.\n" );
     404    DEBUG_ABORT( __actor_executor_ == 0p, "Creating actor before calling start_actor_system() can cause undefined behaviour.\n" );
    403405    allocation_ = Nodelete;
    404406    ticket = __get_next_ticket( *__actor_executor_ );
     
    430432
    431433struct message {
    432     Allocation allocation_;                     // allocation action
     434    allocation allocation_;                     // allocation action
    433435    inline virtual_dtor;
    434436};
     
    437439    this.allocation_ = Nodelete;
    438440}
    439 static inline void ?{}( message & this, Allocation allocation ) {
    440     memcpy( &this.allocation_, &allocation, sizeof(allocation) ); // optimization to elide ctor
    441     verifyf( this.allocation_ != Finished, "The Finished Allocation status is not supported for message types.\n");
     441static inline void ?{}( message & this, allocation alloc ) {
     442    memcpy( &this.allocation_, &alloc, sizeof(allocation) ); // optimization to elide ctor
     443    DEBUG_ABORT( this.allocation_ == Finished, "The Finished allocation status is not supported for message types.\n" );
    442444}
    443445static inline void ^?{}( message & this ) with(this) {
     
    453455    } // switch
    454456}
    455 static inline void set_allocation( message & this, Allocation state ) {
     457static inline void set_allocation( message & this, allocation state ) {
    456458    this.allocation_ = state;
    457459}
    458460
    459461static inline void deliver_request( request & this ) {
    460     verifyf( this.receiver->ticket != (unsigned long int)MAX, "Attempted to send message to deleted/dead actor\n" );
     462    DEBUG_ABORT( this.receiver->ticket == (unsigned long int)MAX, "Attempted to send message to deleted/dead actor\n" );
    461463    this.receiver->allocation_ = this.fn( *this.receiver, *this.msg );
    462464    check_message( *this.msg );
     
    632634
    633635static inline void send( actor & this, request & req ) {
    634     verifyf( this.ticket != (unsigned long int)MAX, "Attempted to send message to deleted/dead actor\n" );
     636    DEBUG_ABORT( this.ticket == (unsigned long int)MAX, "Attempted to send message to deleted/dead actor\n" );
    635637    send( *__actor_executor_, req, this.ticket );
    636638}
     
    685687struct __finished_msg_t { inline message; } finished_msg = __base_msg_finished;
    686688
    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 
     689allocation receive( actor & this, __delete_msg_t & msg ) { return Delete; }
     690allocation receive( actor & this, __destroy_msg_t & msg ) { return Destroy; }
     691allocation receive( actor & this, __finished_msg_t & msg ) { return Finished; }
     692
Note: See TracChangeset for help on using the changeset viewer.