Changeset 713905fd for libcfa/src/concurrency/coroutine.cfa
- Timestamp:
- Jul 10, 2023, 11:14:13 AM (2 years ago)
- Branches:
- master
- Children:
- c3f7dd9
- Parents:
- e6e1a12 (diff), b29a1e8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/coroutine.cfa
re6e1a12 r713905fd 121 121 last = 0p; 122 122 cancellation = 0p; 123 ehm_state.ehm_buffer{}; 124 ehm_state.buffer_lock{}; 125 ehm_state.ehm_enabled = false; 123 126 } 124 127 … … 283 286 } 284 287 288 289 //////////////////////////////////////////////////////////////////////////////////////////////////// 290 // non local ehm routines 291 292 // helper for popping from coroutine's ehm buffer 293 inline nonlocal_exception * pop_ehm_head( coroutine$ * this ) { 294 lock( this->ehm_state.buffer_lock __cfaabi_dbg_ctx2 ); 295 nonlocal_exception * nl_ex = pop_head( this->ehm_state.ehm_buffer ); 296 unlock( this->ehm_state.buffer_lock ); 297 return nl_ex; 298 } 299 300 // user facing ehm operations 301 forall(T & | is_coroutine(T)) { 302 // enable/disable non-local exceptions 303 void enable_ehm( T & cor ) libcfa_public { get_coroutine( cor )->ehm_state.ehm_enabled = true; } 304 void disable_ehm( T & cor ) libcfa_public { get_coroutine( cor )->ehm_state.ehm_enabled = false; } 305 306 // poll for non-local exceptions 307 bool poll( T & cor ) libcfa_public { 308 coroutine$ * base_cor = get_coroutine( cor ); 309 nonlocal_exception * nl_ex = pop_ehm_head( base_cor ); 310 311 // if no exceptions return false 312 if ( nl_ex == 0p ) return false; 313 314 // otherwise loop and throwResume all pending exceptions 315 while ( nl_ex != 0p ){ 316 exception_t * ex = nl_ex->the_exception; 317 free( nl_ex ); 318 throwResume *ex; 319 nl_ex = pop_ehm_head( base_cor ); 320 } 321 322 return true; 323 } 324 325 // poll iff nonlocal ehm is enabled 326 bool checked_poll( T & cor ) libcfa_public { return get_coroutine( cor )->ehm_state.ehm_enabled ? poll( cor ) : false; } 327 } 328 329 // resume non local exception at receiver (i.e. enqueue in ehm buffer) 330 forall(exceptT &, T & | ehm_resume_at( exceptT, T )) 331 void resumeAt( T & receiver, exceptT & ex ) libcfa_public { 332 coroutine$ * cor = get_coroutine( receiver ); 333 nonlocal_exception * nl_ex = alloc(); 334 (*nl_ex){ (exception_t *)&ex }; 335 lock( cor->ehm_state.buffer_lock __cfaabi_dbg_ctx2 ); 336 append( cor->ehm_state.ehm_buffer, nl_ex ); 337 unlock( cor->ehm_state.buffer_lock ); 338 } 339 285 340 // Local Variables: // 286 341 // mode: c //
Note:
See TracChangeset
for help on using the changeset viewer.