Ignore:
Timestamp:
Jul 10, 2026, 9:45:48 AM (6 days ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
c62013e
Parents:
28201f82
Message:

change unnamed enumeration to named and hide the enums to prevent name clashes

File:
1 edited

Legend:

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

    r28201f82 rf41b161  
    1010// Created On       : Wed Jan 06 17:33:18 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Mar 29 22:47:01 2026
    13 // Update Count     : 224
     12// Last Modified On : Fri Jul 10 07:16:22 2026
     13// Update Count     : 232
    1414//
    1515
     
    3939        } // distribution
    4040
    41         enum { FUTURE_EMPTY$ = 0, FUTURE_FULFILLED$ = 1 };
     41        enum future_state$ ! { EMPTY, FULFILLED };
    4242
    4343        // PUBLIC
    4444
    4545        struct future {
    46                 int state;
     46                future_state$ state;
    4747                T result;
    4848                exception_t * except;
     
    5959
    6060                        // check if we can complete operation. If so race to establish winner in special OR case
    61                         if ( !s.park_counter && state != FUTURE_EMPTY$ ) {
     61                        if ( !s.park_counter && state != future_state$.EMPTY ) {
    6262                                if ( !__make_select_node_available( s ) ) { // we didn't win the race so give up on registering
    6363                                        unlock( lock );
     
    6767
    6868                        // future not ready -> insert select node and return
    69                   if ( state == FUTURE_EMPTY$ ) {
     69                  if ( state == future_state$.EMPTY ) {
    7070                                insert_last( waiters, s );
    7171                                unlock( lock );
     
    9999                void ?{}( future(T) & fut ) with( fut ) {
    100100                        except = 0p;
    101                         state = FUTURE_EMPTY$;
     101                        state = future_state$.EMPTY;
    102102                }
    103103
     
    123123
    124124                        // LOCK ACQUIRED IN PUBLIC get
    125                         if ( state == FUTURE_FULFILLED$ ) {
     125                        if ( state == future_state$.FULFILLED ) {
    126126                                exceptCheck();
    127127                                copy_T$( ret_val, result );
     
    140140                // PUBLIC
    141141
    142                 bool available( future( T ) & fut ) { return __atomic_load_n( &fut.state, __ATOMIC_RELAXED ); } // future result available ?
     142                bool available( future( T ) & fut ) { return fut.state == future_state$.FULFILLED; } // future result available ?
    143143
    144144                // Return a value/exception from the future.
    145145                [T, bool] get( future(T) & fut ) with( fut ) {
    146146                        lock( lock );
    147                         bool ret = state == FUTURE_EMPTY$;
     147                        bool ret = state == future_state$.EMPTY;
    148148                        return [ get$( fut ), ret ];
    149149                }
     
    159159                        lock( lock );
    160160                        T ret_val;
    161                         if ( state == FUTURE_FULFILLED$ ) {
     161                        if ( state == future_state$.FULFILLED ) {
    162162                                copy_T$( ret_val, result );
    163163                                unlock( lock );
     
    174174                bool fulfil$( future(T) & fut ) with( fut ) {   // helper
    175175                        bool ret_val = ! empty( waiters );
    176                         state = FUTURE_FULFILLED$;
     176                        state = future_state$.FULFILLED;
    177177                        while ( ! empty( waiters ) ) {
    178178                                if ( !__handle_waituntil_OR( waiters ) ) // handle special waituntil OR case
     
    194194                bool fulfil( future(T) & fut, T val ) with( fut ) {
    195195                        lock( lock );
    196                   if ( state != FUTURE_EMPTY$ ) abort("Attempting to fulfil a future that has already been fulfilled");
     196                  if ( state != future_state$.EMPTY ) abort("Attempting to fulfil a future that has already been fulfilled");
    197197                        copy_T$( result, val );
    198198                        return fulfil$( fut );
     
    202202                bool fulfil( future(T) & fut, exception_t * ex ) with( fut ) {
    203203                        lock( lock );
    204                   if ( state != FUTURE_EMPTY$ ) abort( "Attempting to fulfil a future that has already been fulfilled" );
     204                  if ( state != future_state$.EMPTY ) abort( "Attempting to fulfil a future that has already been fulfilled" );
    205205                        except = ( exception_t * ) malloc( ex->virtual_table->size );
    206206                        ex->virtual_table->copy( except, ex );
     
    212212                        lock( lock );
    213213                  if ( ! empty( waiters ) ) abort( "Attempting to reset a future with blocked waiters" );
    214                         state = FUTURE_EMPTY$;
     214                        state = future_state$.EMPTY;
    215215                        free( except );
    216216                        except = 0p;
Note: See TracChangeset for help on using the changeset viewer.