Changeset 8a930c03 for libcfa/src/concurrency/actor.hfa
- Timestamp:
- Jun 12, 2023, 12:05:58 PM (17 months ago)
- Branches:
- master
- Children:
- fec8bd1
- Parents:
- 2b78949 (diff), 38e266ca (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/actor.hfa
r2b78949 r8a930c03 13 13 #endif // CFA_DEBUG 14 14 15 #define DEBUG_ABORT( cond, string ) CFA_DEBUG( if ( cond ) abort( string ) ) 16 15 17 // Define the default number of processors created in the executor. Must be greater than 0. 16 18 #define __DEFAULT_EXECUTOR_PROCESSORS__ 2 … … 42 44 struct executor; 43 45 44 enum Allocation { Nodelete, Delete, Destroy, Finished }; // allocation status45 46 typedef Allocation (*__receive_fn)(actor &, message &);46 enum allocation { Nodelete, Delete, Destroy, Finished }; // allocation status 47 48 typedef allocation (*__receive_fn)(actor &, message &); 47 49 struct request { 48 50 actor * receiver; … … 393 395 struct actor { 394 396 size_t ticket; // executor-queue handle 395 Allocation allocation_; // allocation action397 allocation allocation_; // allocation action 396 398 inline virtual_dtor; 397 399 }; … … 400 402 // Once an actor is allocated it must be sent a message or the actor system cannot stop. Hence, its receive 401 403 // 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" ); 403 405 allocation_ = Nodelete; 404 406 ticket = __get_next_ticket( *__actor_executor_ ); … … 430 432 431 433 struct message { 432 Allocation allocation_; // allocation action434 allocation allocation_; // allocation action 433 435 inline virtual_dtor; 434 436 }; … … 437 439 this.allocation_ = Nodelete; 438 440 } 439 static inline void ?{}( message & this, Allocation allocation) {440 memcpy( &this.allocation_, &alloc ation, sizeof(allocation) ); // optimization to elide ctor441 verifyf( this.allocation_ != Finished, "The Finished Allocation status is not supported for message types.\n");441 static 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" ); 442 444 } 443 445 static inline void ^?{}( message & this ) with(this) { … … 453 455 } // switch 454 456 } 455 static inline void set_allocation( message & this, Allocation state ) {457 static inline void set_allocation( message & this, allocation state ) { 456 458 this.allocation_ = state; 457 459 } 458 460 459 461 static inline void deliver_request( request & this ) { 462 DEBUG_ABORT( this.receiver->ticket == (unsigned long int)MAX, "Attempted to send message to deleted/dead actor\n" ); 460 463 this.receiver->allocation_ = this.fn( *this.receiver, *this.msg ); 461 464 check_message( *this.msg ); … … 631 634 632 635 static inline void send( actor & this, request & req ) { 633 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" ); 634 637 send( *__actor_executor_, req, this.ticket ); 635 638 } … … 680 683 // assigned at creation to __base_msg_finished to avoid unused message warning 681 684 message __base_msg_finished @= { .allocation_ : Finished }; 682 struct __ DeleteMsg { inline message; } DeleteMsg = __base_msg_finished;683 struct __ DestroyMsg { inline message; } DestroyMsg = __base_msg_finished;684 struct __ FinishedMsg { inline message; } FinishedMsg = __base_msg_finished;685 686 Allocation receive( actor & this, __DeleteMsg& msg ) { return Delete; }687 Allocation receive( actor & this, __DestroyMsg& msg ) { return Destroy; }688 Allocation receive( actor & this, __FinishedMsg& msg ) { return Finished; }689 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
Note: See TracChangeset
for help on using the changeset viewer.