Ignore:
Timestamp:
Apr 24, 2021, 8:10:15 PM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
c323837, fb0be05
Parents:
254ad1b
Message:

futures now optionally don't unpark the target thread

Location:
libcfa/src/concurrency
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/io/types.hfa

    r254ad1b ra76efc8  
    179179
    180180static inline {
    181         bool fulfil( io_future_t & this, __s32 result ) {
     181        $thread * fulfil( io_future_t & this, __s32 result, bool do_unpark = true ) {
    182182                this.result = result;
    183                 return fulfil(this.self);
     183                return fulfil(this.self, do_unpark);
    184184        }
    185185
  • libcfa/src/concurrency/kernel/fwd.hfa

    r254ad1b ra76efc8  
    219219                        // Mark as fulfilled, wake thread if needed
    220220                        // return true if a thread was unparked
    221                         bool post(oneshot & this) {
     221                        $thread * post(oneshot & this, bool do_unpark = true) {
    222222                                struct $thread * got = __atomic_exchange_n( &this.ptr, 1p, __ATOMIC_SEQ_CST);
    223                                 if( got == 0p ) return false;
    224                                 unpark( got );
    225                                 return true;
     223                                if( got == 0p ) return 0p;
     224                                if(do_unpark) unpark( got );
     225                                return got;
    226226                        }
    227227                }
     
    335335                        // from the server side, mark the future as fulfilled
    336336                        // delete it if needed
    337                         bool fulfil( future_t & this ) {
     337                        $thread * fulfil( future_t & this, bool do_unpark = true ) {
    338338                                for() {
    339339                                        struct oneshot * expected = this.ptr;
     
    343343                                                #pragma GCC diagnostic ignored "-Wfree-nonheap-object"
    344344                                        #endif
    345                                                 if( expected == 3p ) { free( &this ); return false; }
     345                                                if( expected == 3p ) { free( &this ); return 0p; }
    346346                                        #if defined(__GNUC__) && __GNUC__ >= 7
    347347                                                #pragma GCC diagnostic pop
     
    355355                                        struct oneshot * want = expected == 0p ? 1p : 2p;
    356356                                        if(__atomic_compare_exchange_n(&this.ptr, &expected, want, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    357                                                 if( expected == 0p ) { /* paranoid */ verify( this.ptr == 1p); return false; }
    358                                                 bool ret = post( *expected );
     357                                                if( expected == 0p ) { /* paranoid */ verify( this.ptr == 1p); return 0p; }
     358                                                $thread * ret = post( *expected, do_unpark );
    359359                                                __atomic_store_n( &this.ptr, 1p, __ATOMIC_SEQ_CST);
    360360                                                return ret;
Note: See TracChangeset for help on using the changeset viewer.