Changeset 7a2c6b18 for libcfa/src/concurrency
- Timestamp:
- Jul 20, 2023, 2:09:15 PM (16 months ago)
- Branches:
- master
- Children:
- 0e8f4c6
- Parents:
- a09552d
- Location:
- libcfa/src/concurrency
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/channel.hfa
ra09552d r7a2c6b18 68 68 #endif 69 69 }; 70 static inline void ?{}( channel(T) & this, channel(T) this2 ) = void; 71 static inline void ?=?( channel(T) & this, channel(T) this2 ) = void; 70 72 71 73 static inline void ?{}( channel(T) &c, size_t _size ) with(c) { … … 372 374 // type used by select statement to capture a chan read as the selected operation 373 375 struct chan_read { 374 T &ret;375 channel(T) &chan;376 T * ret; 377 channel(T) * chan; 376 378 }; 377 379 __CFA_SELECT_GET_TYPE( chan_read(T) ); 378 380 379 static inline void ?{}( chan_read(T) & cr, channel(T) & chan, T &ret ) {380 &cr.chan = &chan;381 &cr.ret = &ret;382 } 383 static inline chan_read(T) ?<<?( T & ret, channel(T) & chan ) { chan_read(T) cr{ chan,ret }; return cr; }384 385 static inline void __handle_select_closed_read( chan_read(T) & this, select_node & node ) with( this.chan, this) {386 __closed_remove( chan,ret );381 static inline void ?{}( chan_read(T) & cr, channel(T) * chan, T * ret ) { 382 cr.chan = chan; 383 cr.ret = ret; 384 } 385 static inline chan_read(T) ?<<?( T & ret, channel(T) & chan ) { chan_read(T) cr{ &chan, &ret }; return cr; } 386 387 static inline void __handle_select_closed_read( chan_read(T) & this, select_node & node ) with(*this.chan, this) { 388 __closed_remove( *chan, *ret ); 387 389 // if we get here then the insert succeeded 388 390 __make_select_node_available( node ); 389 391 } 390 392 391 static inline bool register_select( chan_read(T) & this, select_node & node ) with( this.chan, this) {392 lock( mutex_lock ); 393 node.extra = &ret; // set .extra so that if it == 0p later in on_selected it is due to channel close393 static inline bool register_select( chan_read(T) & this, select_node & node ) with(*this.chan, this) { 394 lock( mutex_lock ); 395 node.extra = ret; // set .extra so that if it == 0p later in on_selected it is due to channel close 394 396 395 397 #ifdef CHAN_STATS … … 406 408 407 409 if ( __handle_pending( prods, node ) ) { 408 __prods_handoff( chan,ret );410 __prods_handoff( *chan, *ret ); 409 411 __make_select_node_sat( node ); // need to to mark SAT now that we know operation is done or else threads could get stuck in __mark_select_node 410 412 unlock( mutex_lock ); … … 432 434 ZeroSize: if ( size == 0 && !prods`isEmpty ) { 433 435 if ( !__handle_waituntil_OR( prods ) ) break ZeroSize; 434 __prods_handoff( chan,ret );436 __prods_handoff( *chan, *ret ); 435 437 __set_avail_then_unlock( node, mutex_lock ); 436 438 return true; … … 449 451 450 452 // Remove from buffer 451 __do_remove( chan,ret );453 __do_remove( *chan, *ret ); 452 454 __set_avail_then_unlock( node, mutex_lock ); 453 455 return true; 454 456 } 455 static inline bool unregister_select( chan_read(T) & this, select_node & node ) { return unregister_chan( this.chan, node ); }457 static inline bool unregister_select( chan_read(T) & this, select_node & node ) { return unregister_chan( *this.chan, node ); } 456 458 static inline bool on_selected( chan_read(T) & this, select_node & node ) with(this) { 457 459 if ( unlikely(node.extra == 0p) ) { 458 if ( !exception_in_flight() ) __closed_remove( chan,ret ); // check if woken up due to closed channel460 if ( !exception_in_flight() ) __closed_remove( *chan, *ret ); // check if woken up due to closed channel 459 461 else return false; 460 462 } … … 465 467 // type used by select statement to capture a chan read as the selected operation that doesn't have a param to read to 466 468 struct chan_read_no_ret { 467 T ret ;468 chan_read( T ) c r;469 T retval; 470 chan_read( T ) c_read; 469 471 }; 470 472 __CFA_SELECT_GET_TYPE( chan_read_no_ret(T) ); 471 473 472 474 static inline void ?{}( chan_read_no_ret(T) & this, channel(T) & chan ) { 473 this.cr{ chan, this.ret }; 474 } 475 static inline chan_read_no_ret(T) remove( channel(T) & chan ) { chan_read_no_ret(T) cr{ chan }; return cr; } 476 static inline bool register_select( chan_read_no_ret(T) & this, select_node & node ) { return register_select( this.cr, node ); } 477 static inline bool unregister_select( chan_read_no_ret(T) & this, select_node & node ) { return unregister_select( this.cr, node ); } 478 static inline bool on_selected( chan_read_no_ret(T) & this, select_node & node ) { return on_selected( this.cr, node ); } 475 this.c_read{ &chan, &this.retval }; 476 } 477 478 static inline chan_read_no_ret(T) remove( channel(T) & chan ) { chan_read_no_ret(T) c_read{ chan }; return c_read; } 479 static inline bool register_select( chan_read_no_ret(T) & this, select_node & node ) { 480 this.c_read.ret = &this.retval; 481 return register_select( this.c_read, node ); 482 } 483 static inline bool unregister_select( chan_read_no_ret(T) & this, select_node & node ) { return unregister_select( this.c_read, node ); } 484 static inline bool on_selected( chan_read_no_ret(T) & this, select_node & node ) { return on_selected( this.c_read, node ); } 479 485 480 486 // type used by select statement to capture a chan write as the selected operation 481 487 struct chan_write { 482 488 T elem; 483 channel(T) &chan;489 channel(T) * chan; 484 490 }; 485 491 __CFA_SELECT_GET_TYPE( chan_write(T) ); 486 492 487 static inline void ?{}( chan_write(T) & cw, channel(T) &chan, T elem ) {488 &cw.chan = &chan;493 static inline void ?{}( chan_write(T) & cw, channel(T) * chan, T elem ) { 494 cw.chan = chan; 489 495 memcpy( (void *)&cw.elem, (void *)&elem, sizeof(T) ); 490 496 } 491 static inline chan_write(T) ?<<?( channel(T) & chan, T elem ) { chan_write(T) cw{ chan, elem }; return cw; }492 static inline chan_write(T) insert( T elem, channel(T) & chan) { chan_write(T) cw{ chan, elem }; return cw; }493 494 static inline void __handle_select_closed_write( chan_write(T) & this, select_node & node ) with( this.chan, this) {495 __closed_insert( chan, elem );497 static inline chan_write(T) ?<<?( channel(T) & chan, T elem ) { chan_write(T) cw{ &chan, elem }; return cw; } 498 static inline chan_write(T) insert( T elem, channel(T) & chan) { chan_write(T) cw{ &chan, elem }; return cw; } 499 500 static inline void __handle_select_closed_write( chan_write(T) & this, select_node & node ) with(*this.chan, this) { 501 __closed_insert( *chan, elem ); 496 502 // if we get here then the insert succeeded 497 503 __make_select_node_available( node ); 498 504 } 499 505 500 static inline bool register_select( chan_write(T) & this, select_node & node ) with( this.chan, this) {506 static inline bool register_select( chan_write(T) & this, select_node & node ) with(*this.chan, this) { 501 507 lock( mutex_lock ); 502 508 node.extra = &elem; // set .extra so that if it == 0p later in on_selected it is due to channel close … … 516 522 517 523 if ( __handle_pending( cons, node ) ) { 518 __cons_handoff( chan, elem );524 __cons_handoff( *chan, elem ); 519 525 __make_select_node_sat( node ); // need to to mark SAT now that we know operation is done or else threads could get stuck in __mark_select_node 520 526 unlock( mutex_lock ); … … 543 549 ConsEmpty: if ( !cons`isEmpty ) { 544 550 if ( !__handle_waituntil_OR( cons ) ) break ConsEmpty; 545 __cons_handoff( chan, elem );551 __cons_handoff( *chan, elem ); 546 552 __set_avail_then_unlock( node, mutex_lock ); 547 553 return true; … … 560 566 561 567 // otherwise carry out write either via normal insert 562 __buf_insert( chan, elem );568 __buf_insert( *chan, elem ); 563 569 __set_avail_then_unlock( node, mutex_lock ); 564 570 return true; 565 571 } 566 static inline bool unregister_select( chan_write(T) & this, select_node & node ) { return unregister_chan( this.chan, node ); }572 static inline bool unregister_select( chan_write(T) & this, select_node & node ) { return unregister_chan( *this.chan, node ); } 567 573 568 574 static inline bool on_selected( chan_write(T) & this, select_node & node ) with(this) { 569 575 if ( unlikely(node.extra == 0p) ) { 570 if ( !exception_in_flight() ) __closed_insert( chan, elem ); // check if woken up due to closed channel576 if ( !exception_in_flight() ) __closed_insert( *chan, elem ); // check if woken up due to closed channel 571 577 else return false; 572 578 } -
libcfa/src/concurrency/locks.hfa
ra09552d r7a2c6b18 140 140 }; 141 141 142 static inline void ?{}( mcs_node & this) { this.next = 0p; }142 static inline void ?{}( mcs_node & this ) { this.next = 0p; } 143 143 144 144 static inline mcs_node * volatile & ?`next ( mcs_node * node ) { … … 150 150 }; 151 151 152 static inline void lock( mcs_lock & l, mcs_node & n) {152 static inline void lock( mcs_lock & l, mcs_node & n ) { 153 153 if(push(l.queue, &n)) 154 154 wait(n.sem); … … 174 174 }; 175 175 176 static inline void ?{}( mcs_spin_node & this) { this.next = 0p; this.locked = true; }176 static inline void ?{}( mcs_spin_node & this ) { this.next = 0p; this.locked = true; } 177 177 178 178 struct mcs_spin_lock { … … 180 180 }; 181 181 182 static inline void lock( mcs_spin_lock & l, mcs_spin_node & n) {182 static inline void lock( mcs_spin_lock & l, mcs_spin_node & n ) { 183 183 n.locked = true; 184 184 mcs_spin_node * prev = __atomic_exchange_n(&l.queue.tail, &n, __ATOMIC_SEQ_CST); … … 273 273 }; 274 274 static inline void ?{}( go_mutex & this ) with(this) { val = 0; } 275 // static inline void ?{}( go_mutex & this, go_mutex this2 ) = void; // these don't compile correctly at the moment so they should be omitted 276 //static inline void ?=?( go_mutex & this, go_mutex this2 ) = void;275 static inline void ?{}( go_mutex & this, go_mutex this2 ) = void; 276 static inline void ?=?( go_mutex & this, go_mutex this2 ) = void; 277 277 278 278 static inline bool internal_try_lock(go_mutex & this, int & compare_val, int new_val ) with(this) {
Note: See TracChangeset
for help on using the changeset viewer.