- Timestamp:
- Aug 9, 2023, 3:17:16 PM (18 months ago)
- Branches:
- master
- Children:
- 23edb61, e7a8f65
- Parents:
- 57fd66d
- Location:
- libcfa/src/concurrency
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/coroutine.cfa
r57fd66d r3318dff 28 28 #include "kernel/private.hfa" 29 29 #include "exception.hfa" 30 #include "exception.h" 30 31 #include "math.hfa" 31 32 … … 298 299 } 299 300 301 void defaultResumeAtHandler( exception_t * except ) { 302 __cfaehm_allocate_exception( except ); 303 free( except ); 304 __cfaehm_begin_unwind( (void(*)(exception_t *))defaultTerminationHandler ); 305 } 306 300 307 bool poll( coroutine$ * cor ) libcfa_public { 301 308 nonlocal_exception * nl_ex = pop_ehm_head( cor ); … … 308 315 exception_t * ex = nl_ex->the_exception; 309 316 free( nl_ex ); 310 throwResume *ex; 317 __cfaehm_throw_resume( ex, defaultResumeAtHandler ); 318 319 // only reached if resumption handled. other dealloc handled in defaultResumeAtHandler 320 free( ex ); 311 321 nl_ex = pop_ehm_head( cor ); 312 322 } … … 316 326 317 327 bool poll() libcfa_public { return poll( active_coroutine() ); } 328 coroutine$ * resumer() libcfa_public { return active_coroutine()->last; } 318 329 319 330 // user facing ehm operations … … 333 344 334 345 // resume non local exception at receiver (i.e. enqueue in ehm buffer) 335 forall(exceptT &, T & | ehm_resume_at( exceptT, T ))346 forall(exceptT *, T & | ehm_resume_at( exceptT, T )) 336 347 void resumeAt( T & receiver, exceptT & ex ) libcfa_public { 337 348 coroutine$ * cor = get_coroutine( receiver ); 338 349 nonlocal_exception * nl_ex = alloc(); 339 (*nl_ex){ (exception_t *)&ex }; 350 exceptT * ex_copy = alloc(); 351 memcpy( ex_copy, &ex, sizeof(exceptT) ); 352 (*nl_ex){ (exception_t *)ex_copy }; 340 353 lock( cor->ehm_state.buffer_lock __cfaabi_dbg_ctx2 ); 341 354 append( cor->ehm_state.ehm_buffer, nl_ex ); … … 343 356 } 344 357 345 forall(exceptT &| { void $throwResume(exceptT &); })358 forall(exceptT * | { void $throwResume(exceptT &); }) 346 359 void resumeAt( coroutine$ * receiver, exceptT & ex ) libcfa_public { 347 360 nonlocal_exception * nl_ex = alloc(); 348 (*nl_ex){ (exception_t *)&ex }; 361 exceptT * ex_copy = alloc(); 362 memcpy( ex_copy, &ex, sizeof(exceptT) ); 363 (*nl_ex){ (exception_t *)ex_copy }; 349 364 lock( receiver->ehm_state.buffer_lock __cfaabi_dbg_ctx2 ); 350 365 append( receiver->ehm_state.ehm_buffer, nl_ex ); -
libcfa/src/concurrency/coroutine.hfa
r57fd66d r3318dff 221 221 bool poll( coroutine$ * cor ); 222 222 bool poll(); 223 coroutine$ * resumer(); 223 224 224 225 forall(T & | is_coroutine(T)) { … … 231 232 232 233 // trait for exceptions able to be resumed at another coroutine 233 forall(exceptT &, T & | is_coroutine(T))234 forall(exceptT *, T & | is_coroutine(T)) 234 235 trait ehm_resume_at { void $throwResume(exceptT &); }; 235 236 236 237 // general resumeAt 237 forall(exceptT &, T & | ehm_resume_at( exceptT, T ))238 forall(exceptT *, T & | ehm_resume_at( exceptT, T )) 238 239 void resumeAt( T & receiver, exceptT & ex ); 239 240 240 241 // resumeAt for underlying coroutine$ type 241 forall(exceptT &| { void $throwResume(exceptT &); })242 forall(exceptT * | { void $throwResume(exceptT &); }) 242 243 void resumeAt( coroutine$ * receiver, exceptT & ex ); 243 244
Note: See TracChangeset
for help on using the changeset viewer.