[e23b3ce] | 1 | //
|
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2021 University of Waterloo
|
---|
| 3 | //
|
---|
| 4 | // The contents of this file are covered under the licence agreement in the
|
---|
| 5 | // file "LICENCE" distributed with Cforall.
|
---|
| 6 | //
|
---|
| 7 | // channel.hfa -- LIBCFATHREAD
|
---|
| 8 | // Runtime locks that used with the runtime thread system.
|
---|
| 9 | //
|
---|
| 10 | // Author : Colby Alexander Parsons
|
---|
| 11 | // Created On : Thu Apr 21 19:46:50 2023
|
---|
| 12 | // Last Modified By :
|
---|
| 13 | // Last Modified On :
|
---|
| 14 | // Update Count :
|
---|
| 15 | //
|
---|
| 16 |
|
---|
| 17 | #define __cforall_thread__
|
---|
| 18 | #include "select.hfa"
|
---|
| 19 |
|
---|
| 20 | #pragma GCC visibility push(default)
|
---|
| 21 |
|
---|
| 22 | // As much code as possible is put in select.hfa to allow for inlining,
|
---|
| 23 | // but this .cfa is needed to link with alarm.cfa correctly ( and possibly some other things )
|
---|
| 24 |
|
---|
| 25 | //=============================================================================================
|
---|
| 26 | // Waituntil Timeout support
|
---|
| 27 | //=============================================================================================
|
---|
| 28 |
|
---|
| 29 | void ?{}( select_timeout_node & this, Duration duration, Alarm_Callback callback ) {
|
---|
| 30 | this.a_node{ callback, duration, 0`s };
|
---|
| 31 | }
|
---|
| 32 | void ^?{}( select_timeout_node & this ) {}
|
---|
| 33 |
|
---|
| 34 | void timeout_handler( select_timeout_node & this ) with( this ) {
|
---|
| 35 | if ( !__make_select_node_available( *s_node ) ) return;
|
---|
| 36 | unpark( s_node->blocked_thread );
|
---|
| 37 | }
|
---|
| 38 | void timeout_handler_select_cast( alarm_node_t & node ) { timeout_handler( ((select_timeout_node &) node) ); }
|
---|
| 39 |
|
---|
| 40 | // Selectable trait routines
|
---|
| 41 | bool register_select( select_timeout_node & this, select_node & node ) {
|
---|
| 42 | this.s_node = &node;
|
---|
| 43 | node.extra = 0p;
|
---|
| 44 | register_self( &this.a_node );
|
---|
| 45 | return false;
|
---|
| 46 | }
|
---|
| 47 | bool unregister_select( select_timeout_node & this, select_node & node ) {
|
---|
| 48 | unregister_self( &this.a_node );
|
---|
| 49 | return false;
|
---|
| 50 | }
|
---|
[70a4ed5] | 51 | void on_selected( select_timeout_node & this, select_node & node ) {}
|
---|
[e23b3ce] | 52 |
|
---|
| 53 | // Gateway routine to wait on duration
|
---|
| 54 | select_timeout_node timeout( Duration duration ) {
|
---|
| 55 | select_timeout_node node{ duration, timeout_handler_select_cast };
|
---|
| 56 | return node;
|
---|
| 57 | }
|
---|
| 58 | select_timeout_node sleep( Duration duration ) { return timeout( duration ); }
|
---|
| 59 |
|
---|