Changeset e23b3ce


Ignore:
Timestamp:
May 15, 2023, 1:16:20 PM (14 months ago)
Author:
caparsons <caparson@…>
Branches:
ADT, ast-experimental, master
Children:
100d12d4
Parents:
c0ec8b6
Message:

added support for timeouts in waituntil

Location:
libcfa/src/concurrency
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/select.hfa

    rc0ec8b6 re23b3ce  
     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 Jan 21 19:46:50 2023
     12// Last Modified By :
     13// Last Modified On :
     14// Update Count     :
     15//
     16
    117#pragma once
    218
    319#include "containers/list.hfa"
    4 // #include "alarm.hfa"
    5 #include "stdint.h"
     20#include "alarm.hfa"
    621#include "kernel.hfa"
    722#include "time.hfa"
     
    1429static const unsigned long int __SELECT_SAT = 2;
    1530static const unsigned long int __SELECT_RUN = 3;
    16 
    1731
    1832// these are used inside the compiler to aid in code generation
     
    105119    __atomic_store_n( clause_status, __SELECT_UNSAT, __ATOMIC_SEQ_CST );
    106120}
     121static inline void __make_select_node_sat( select_node & this ) with( this ) {
     122    __atomic_store_n( clause_status, __SELECT_SAT, __ATOMIC_SEQ_CST );
     123}
    107124
    108125static inline bool __make_select_node_pending( select_node & this ) with( this ) {
     
    116133    if( !park_counter )
    117134        return __mark_select_node( this, (unsigned long int)&this );
    118     // return *clause_status == 0
    119     //     && __atomic_compare_exchange_n( clause_status, &cmp_status, (unsigned long int)&this, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST ); // OR specific case where race was won
    120135
    121136    unsigned long int cmp_status = __SELECT_UNSAT;
     
    135150        while ( !queue`isEmpty ) {
    136151            // if node not a special OR case or if we win the special OR case race break
    137             if ( !queue`first.clause_status || queue`first.park_counter || __make_select_node_available( queue`first ) ) { return true; }
     152            if ( !queue`first.clause_status || queue`first.park_counter || __make_select_node_available( queue`first ) )
     153                return true;
    138154            // otherwise we lost the special OR race so discard node
    139155            try_pop_front( queue );
     
    160176}
    161177
     178// waituntil ( timeout( ... ) ) support
     179struct select_timeout_node {
     180    alarm_node_t a_node;
     181    select_node * s_node;
     182};
     183void ?{}( select_timeout_node & this, Duration duration, Alarm_Callback callback );
     184void ^?{}( select_timeout_node & this );
     185void timeout_handler_select_cast( alarm_node_t & node );
    162186
     187// Selectable trait routines
     188bool register_select( select_timeout_node & this, select_node & node );
     189bool unregister_select( select_timeout_node & this, select_node & node );
     190bool on_selected( select_timeout_node & this, select_node & node );
     191
     192// Gateway routines to waituntil on duration
     193select_timeout_node timeout( Duration duration );
     194select_timeout_node sleep( Duration duration );
Note: See TracChangeset for help on using the changeset viewer.