Changeset 23edb61


Ignore:
Timestamp:
Aug 10, 2023, 2:53:42 PM (10 months ago)
Author:
caparsons <caparson@…>
Branches:
master
Children:
9ff71ff
Parents:
3318dff
Message:

added warning message and cleanup for unhandled pending non-local exceptions on coroutine shutdown

File:
1 edited

Legend:

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

    r3318dff r23edb61  
    7878        free( desc->cancellation );
    7979        desc->cancellation = 0p;
     80}
     81
     82// helper for popping from coroutine's ehm buffer
     83inline nonlocal_exception * pop_ehm_head( coroutine$ * this ) {
     84    lock( this->ehm_state.buffer_lock __cfaabi_dbg_ctx2 );
     85    nonlocal_exception * nl_ex = pop_head( this->ehm_state.ehm_buffer );
     86    unlock( this->ehm_state.buffer_lock );
     87    return nl_ex;
    8088}
    8189
     
    128136
    129137void ^?{}(coroutine$& this) libcfa_public {
     138    // handle any leftover pending non-local exceptions
     139    nonlocal_exception * nl_ex = pop_ehm_head( &this );
     140    unsigned unhandled_ex = 0;
     141   
     142    // if any leftover exceptions handle
     143    while ( nl_ex != 0p ){
     144        unhandled_ex++;
     145        free( nl_ex->the_exception );
     146        free( nl_ex );
     147        nl_ex = pop_ehm_head( &this );
     148    }
     149
     150    #ifdef __CFA_DEBUG__
     151    if ( unhandled_ex > 0 )
     152        printf( "Warning: Coroutine %p exited with %u pending nonlocal exceptions.\n", &this, unhandled_ex );
     153    #endif
     154
    130155        if(this.state != Halted && this.state != Start && this.state != Primed) {
    131156                coroutine$ * src = active_coroutine();
     
    291316// non local ehm routines
    292317
    293 // helper for popping from coroutine's ehm buffer
    294 inline nonlocal_exception * pop_ehm_head( coroutine$ * this ) {
    295     lock( this->ehm_state.buffer_lock __cfaabi_dbg_ctx2 );
    296     nonlocal_exception * nl_ex = pop_head( this->ehm_state.ehm_buffer );
    297     unlock( this->ehm_state.buffer_lock );
    298     return nl_ex;
    299 }
    300 
    301318void defaultResumeAtHandler( exception_t * except ) {
    302319    __cfaehm_allocate_exception( except );
Note: See TracChangeset for help on using the changeset viewer.