Changeset 0794365
- Timestamp:
- Jun 4, 2023, 8:38:45 AM (23 months ago)
- Branches:
- ast-experimental, master
- Children:
- c880a7b
- Parents:
- 46e6e47
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified libcfa/src/concurrency/actor.hfa ¶
r46e6e47 r0794365 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 ) { 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" ); 461 463 this.receiver->allocation_ = this.fn( *this.receiver, *this.msg ); 462 464 check_message( *this.msg ); … … 632 634 633 635 static 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" ); 635 637 send( *__actor_executor_, req, this.ticket ); 636 638 } … … 685 687 struct __finished_msg_t { inline message; } finished_msg = __base_msg_finished; 686 688 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 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 -
TabularUnified src/Concurrency/Actors.cpp ¶
r46e6e47 r0794365 38 38 bool namedDecl = false; 39 39 40 // finds and sets a ptr to the Allocation enum, which is needed in the next pass40 // finds and sets a ptr to the allocation enum, which is needed in the next pass 41 41 void previsit( const EnumDecl * decl ) { 42 if( decl->name == " Allocation" ) *allocationDecl = decl;42 if( decl->name == "allocation" ) *allocationDecl = decl; 43 43 } 44 44 … … 227 227 static inline derived_actor & ?|?( derived_actor & receiver, derived_msg & msg ) { 228 228 request new_req; 229 Allocation (*my_work_fn)( derived_actor &, derived_msg & ) = receive;229 allocation (*my_work_fn)( derived_actor &, derived_msg & ) = receive; 230 230 __receive_fn fn = (__receive_fn)my_work_fn; 231 231 new_req{ &receiver, &msg, fn }; … … 246 246 )); 247 247 248 // Function type is: Allocation (*)( derived_actor &, derived_msg & )248 // Function type is: allocation (*)( derived_actor &, derived_msg & ) 249 249 FunctionType * derivedReceive = new FunctionType(); 250 250 derivedReceive->params.push_back( ast::deepCopy( derivedActorRef ) ); … … 252 252 derivedReceive->returns.push_back( new EnumInstType( *allocationDecl ) ); 253 253 254 // Generates: Allocation (*my_work_fn)( derived_actor &, derived_msg & ) = receive;254 // Generates: allocation (*my_work_fn)( derived_actor &, derived_msg & ) = receive; 255 255 sendBody->push_back( new DeclStmt( 256 256 decl->location, … … 263 263 )); 264 264 265 // Function type is: Allocation (*)( actor &, message & )265 // Function type is: allocation (*)( actor &, message & ) 266 266 FunctionType * genericReceive = new FunctionType(); 267 267 genericReceive->params.push_back( new ReferenceType( new StructInstType( *actorDecl ) ) ); … … 269 269 genericReceive->returns.push_back( new EnumInstType( *allocationDecl ) ); 270 270 271 // Generates: Allocation (*fn)( actor &, message & ) = (Allocation (*)( actor &, message & ))my_work_fn;271 // Generates: allocation (*fn)( actor &, message & ) = (allocation (*)( actor &, message & ))my_work_fn; 272 272 // More readable synonymous code: 273 // typedef Allocation (*__receive_fn)(actor &, message &);273 // typedef allocation (*__receive_fn)(actor &, message &); 274 274 // __receive_fn fn = (__receive_fn)my_work_fn; 275 275 sendBody->push_back( new DeclStmt( … … 422 422 const StructDecl ** msgDecl = &msgDeclPtr; 423 423 424 // first pass collects ptrs to Allocation enum, request type, and generic receive fn typedef424 // first pass collects ptrs to allocation enum, request type, and generic receive fn typedef 425 425 // also populates maps of all derived actors and messages 426 426 Pass<CollectactorStructDecls>::run( translationUnit, actorStructDecls, messageStructDecls, requestDecl,
Note: See TracChangeset
for help on using the changeset viewer.