Ignore:
Timestamp:
Aug 20, 2020, 11:48:15 PM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
d685cb0
Parents:
67ca73e (diff), 013b028 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

fix conflicts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/bits/locks.hfa

    r67ca73e re67a82d  
    217217                }
    218218        }
     219
     220        // Semaphore which only supports a single thread and one post
     221        // Semaphore which only supports a single thread
     222        struct oneshot {
     223                struct $thread * volatile ptr;
     224        };
     225
     226        static inline {
     227                void  ?{}(oneshot & this) {
     228                        this.ptr = 0p;
     229                }
     230
     231                void ^?{}(oneshot & this) {}
     232
     233                bool wait(oneshot & this) {
     234                        for() {
     235                                struct $thread * expected = this.ptr;
     236                                if(expected == 1p) return false;
     237                                /* paranoid */ verify( expected == 0p );
     238                                if(__atomic_compare_exchange_n(&this.ptr, &expected, active_thread(), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
     239                                        park( __cfaabi_dbg_ctx );
     240                                        /* paranoid */ verify( this.ptr == 1p );
     241                                        return true;
     242                                }
     243                        }
     244                }
     245
     246                bool post(oneshot & this) {
     247                        struct $thread * got = __atomic_exchange_n( &this.ptr, 1p, __ATOMIC_SEQ_CST);
     248                        if( got == 0p ) return false;
     249                        unpark( got __cfaabi_dbg_ctx2 );
     250                        return true;
     251                }
     252        }
    219253#endif
Note: See TracChangeset for help on using the changeset viewer.