Changeset e8b8e65


Ignore:
Timestamp:
Oct 31, 2022, 4:39:28 PM (18 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, master
Children:
1dafdfc
Parents:
7f3b5ce
Message:

Added implementation of call_once

Files:
3 added
2 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/Makefile.am

    r7f3b5ce re8b8e65  
    111111        concurrency/invoke.h \
    112112        concurrency/future.hfa \
     113        concurrency/once.hfa \
    113114        concurrency/kernel/fwd.hfa \
    114115        concurrency/mutex_stmt.hfa
  • libcfa/src/containers/lockfree.hfa

    r7f3b5ce re8b8e65  
    142142
    143143        static inline void ?{}(poison_list(T) & this) { this.head = 0p; }
     144        static inline bool is_poisoned( const poison_list(T) & this ) { return 1p == this.head; }
    144145
    145146        static inline forall(| { T * volatile & ?`next ( T * ); })
     
    147148                // Adds an element to the list
    148149                // Multi-Thread Safe, Lock-Free
    149                 T * push(poison_list(T) & this, T * elem) __attribute__((artificial));
    150                 T * push(poison_list(T) & this, T * elem) {
     150                bool push(poison_list(T) & this, T * elem) __attribute__((artificial));
     151                bool push(poison_list(T) & this, T * elem) {
    151152                        /* paranoid */ verify(0p == (elem`next));
    152153                        __atomic_store_n( &elem`next, (T*)1p, __ATOMIC_RELAXED );
     
    156157                        for() {
    157158                                // check if it's poisoned
    158                                 if(expected == 1p) return 0p;
     159                                if(expected == 1p) return false;
    159160
    160161                                // try to CAS the elem in
     
    162163                                        // We managed to exchange in, we are done
    163164
    164                                         // We should never succeed the CAS if it's poisonned.
    165                                         /* paranoid */ verify( expected != 1p );
     165                                        // We should never succeed the CAS if it's poisonned and the elem should be 1p.
     166                                        /* paranoid */ verify( expected  != 1p );
     167                                        /* paranoid */ verify( elem`next == 1p );
    166168
    167169                                        // If we aren't the first, we need to tell the person before us
    168170                                        // No need to
    169171                                        elem`next = expected;
    170                                         return expected;
     172                                        return true;
    171173                                }
    172174                        }
     
    190192                T * poison(poison_list(T) & this) {
    191193                        T * ret = __atomic_exchange_n( &this.head, (T*)1p, __ATOMIC_SEQ_CST );
    192                         /* paranoid */ verify( ret != (T*)1p );
     194                        /* paranoid */ verifyf( ret != (T*)1p, "Poison list %p poisoned more than once!", &this );
    193195                        return ret;
    194196                }
Note: See TracChangeset for help on using the changeset viewer.