source: libcfa/src/concurrency/select.cfa @ 1d66a91

Last change on this file since 1d66a91 was b93bf85, checked in by caparsons <caparson@…>, 16 months ago

fixed spurious channel close waituntil error case. Was caused by a race condition causing an exception to be thrown while another was in flight

  • Property mode set to 100644
File size: 2.0 KB
Line 
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
29void ?{}( select_timeout_node & this, Duration duration, Alarm_Callback callback ) {
30    this.a_node{ callback, duration, 0`s };
31}
32void ^?{}( select_timeout_node & this ) {}
33
34void timeout_handler( select_timeout_node & this ) with( this ) {
35    if ( !__make_select_node_available( *s_node ) ) return;
36    unpark( s_node->blocked_thread );
37}
38void timeout_handler_select_cast( alarm_node_t & node ) { timeout_handler( ((select_timeout_node &) node) ); }
39
40// Selectable trait routines
41bool 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}
47bool unregister_select( select_timeout_node & this, select_node & node ) {
48    unregister_self( &this.a_node );
49    return false;
50}
51bool on_selected( select_timeout_node & this, select_node & node ) { return true; }
52
53// Gateway routine to wait on duration
54select_timeout_node timeout( Duration duration ) {
55        select_timeout_node node{ duration, timeout_handler_select_cast };
56    return node;
57}
58select_timeout_node sleep( Duration duration ) { return timeout( duration ); }
59
Note: See TracBrowser for help on using the repository browser.