Changeset f41b161 for libcfa/src/concurrency/future.hfa
- Timestamp:
- Jul 10, 2026, 9:45:48 AM (6 days ago)
- Branches:
- master
- Children:
- c62013e
- Parents:
- 28201f82
- File:
-
- 1 edited
-
libcfa/src/concurrency/future.hfa (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/future.hfa
r28201f82 rf41b161 10 10 // Created On : Wed Jan 06 17:33:18 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Mar 29 22:47:01202613 // Update Count : 2 2412 // Last Modified On : Fri Jul 10 07:16:22 2026 13 // Update Count : 232 14 14 // 15 15 … … 39 39 } // distribution 40 40 41 enum { FUTURE_EMPTY$ = 0, FUTURE_FULFILLED$ = 1};41 enum future_state$ ! { EMPTY, FULFILLED }; 42 42 43 43 // PUBLIC 44 44 45 45 struct future { 46 intstate;46 future_state$ state; 47 47 T result; 48 48 exception_t * except; … … 59 59 60 60 // 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 ) { 62 62 if ( !__make_select_node_available( s ) ) { // we didn't win the race so give up on registering 63 63 unlock( lock ); … … 67 67 68 68 // future not ready -> insert select node and return 69 if ( state == FUTURE_EMPTY$) {69 if ( state == future_state$.EMPTY ) { 70 70 insert_last( waiters, s ); 71 71 unlock( lock ); … … 99 99 void ?{}( future(T) & fut ) with( fut ) { 100 100 except = 0p; 101 state = FUTURE_EMPTY$;101 state = future_state$.EMPTY; 102 102 } 103 103 … … 123 123 124 124 // LOCK ACQUIRED IN PUBLIC get 125 if ( state == FUTURE_FULFILLED$) {125 if ( state == future_state$.FULFILLED ) { 126 126 exceptCheck(); 127 127 copy_T$( ret_val, result ); … … 140 140 // PUBLIC 141 141 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 ? 143 143 144 144 // Return a value/exception from the future. 145 145 [T, bool] get( future(T) & fut ) with( fut ) { 146 146 lock( lock ); 147 bool ret = state == FUTURE_EMPTY$;147 bool ret = state == future_state$.EMPTY; 148 148 return [ get$( fut ), ret ]; 149 149 } … … 159 159 lock( lock ); 160 160 T ret_val; 161 if ( state == FUTURE_FULFILLED$) {161 if ( state == future_state$.FULFILLED ) { 162 162 copy_T$( ret_val, result ); 163 163 unlock( lock ); … … 174 174 bool fulfil$( future(T) & fut ) with( fut ) { // helper 175 175 bool ret_val = ! empty( waiters ); 176 state = FUTURE_FULFILLED$;176 state = future_state$.FULFILLED; 177 177 while ( ! empty( waiters ) ) { 178 178 if ( !__handle_waituntil_OR( waiters ) ) // handle special waituntil OR case … … 194 194 bool fulfil( future(T) & fut, T val ) with( fut ) { 195 195 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"); 197 197 copy_T$( result, val ); 198 198 return fulfil$( fut ); … … 202 202 bool fulfil( future(T) & fut, exception_t * ex ) with( fut ) { 203 203 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" ); 205 205 except = ( exception_t * ) malloc( ex->virtual_table->size ); 206 206 ex->virtual_table->copy( except, ex ); … … 212 212 lock( lock ); 213 213 if ( ! empty( waiters ) ) abort( "Attempting to reset a future with blocked waiters" ); 214 state = FUTURE_EMPTY$;214 state = future_state$.EMPTY; 215 215 free( except ); 216 216 except = 0p;
Note:
See TracChangeset
for help on using the changeset viewer.