Changeset 3318dff


Ignore:
Timestamp:
Aug 9, 2023, 3:17:16 PM (10 months ago)
Author:
caparsons <caparson@…>
Branches:
master
Children:
23edb61, e7a8f65
Parents:
57fd66d
Message:

fixed non-local ehm issue and added no arg resumer routine

Location:
libcfa/src/concurrency
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/coroutine.cfa

    r57fd66d r3318dff  
    2828#include "kernel/private.hfa"
    2929#include "exception.hfa"
     30#include "exception.h"
    3031#include "math.hfa"
    3132
     
    298299}
    299300
     301void defaultResumeAtHandler( exception_t * except ) {
     302    __cfaehm_allocate_exception( except );
     303    free( except );
     304    __cfaehm_begin_unwind( (void(*)(exception_t *))defaultTerminationHandler );
     305}
     306
    300307bool poll( coroutine$ * cor ) libcfa_public {
    301308    nonlocal_exception * nl_ex = pop_ehm_head( cor );
     
    308315        exception_t * ex = nl_ex->the_exception;
    309316        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 );
    311321        nl_ex = pop_ehm_head( cor );
    312322    }
     
    316326
    317327bool poll() libcfa_public { return poll( active_coroutine() ); }
     328coroutine$ * resumer() libcfa_public { return active_coroutine()->last; }
    318329
    319330// user facing ehm operations
     
    333344
    334345// resume non local exception at receiver (i.e. enqueue in ehm buffer)
    335 forall(exceptT &, T & | ehm_resume_at( exceptT, T ))
     346forall(exceptT *, T & | ehm_resume_at( exceptT, T ))
    336347void resumeAt( T & receiver, exceptT & ex )  libcfa_public {
    337348    coroutine$ * cor = get_coroutine( receiver );
    338349    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 };
    340353    lock( cor->ehm_state.buffer_lock __cfaabi_dbg_ctx2 );
    341354    append( cor->ehm_state.ehm_buffer, nl_ex );
     
    343356}
    344357
    345 forall(exceptT & | { void $throwResume(exceptT &); })
     358forall(exceptT * | { void $throwResume(exceptT &); })
    346359void resumeAt( coroutine$ * receiver, exceptT & ex ) libcfa_public {
    347360    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 };
    349364    lock( receiver->ehm_state.buffer_lock __cfaabi_dbg_ctx2 );
    350365    append( receiver->ehm_state.ehm_buffer, nl_ex );
  • libcfa/src/concurrency/coroutine.hfa

    r57fd66d r3318dff  
    221221bool poll( coroutine$ * cor );
    222222bool poll();
     223coroutine$ * resumer();
    223224
    224225forall(T & | is_coroutine(T)) {
     
    231232
    232233// trait for exceptions able to be resumed at another coroutine
    233 forall(exceptT &, T & | is_coroutine(T))
     234forall(exceptT *, T & | is_coroutine(T))
    234235trait ehm_resume_at { void $throwResume(exceptT &); };
    235236
    236237// general resumeAt
    237 forall(exceptT &, T & | ehm_resume_at( exceptT, T ))
     238forall(exceptT *, T & | ehm_resume_at( exceptT, T ))
    238239void resumeAt( T & receiver, exceptT & ex );
    239240
    240241// resumeAt for underlying coroutine$ type
    241 forall(exceptT & | { void $throwResume(exceptT &); })
     242forall(exceptT * | { void $throwResume(exceptT &); })
    242243void resumeAt( coroutine$ * receiver, exceptT & ex );
    243244
Note: See TracChangeset for help on using the changeset viewer.