Ignore:
File:
1 edited

Legend:

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

    re0f93e0 rb353a49  
    130130                pthread_mutex_init(&lock, &mattr);
    131131
    132                 pthread_cond_init (&cond, 0p);
     132                pthread_cond_init (&cond, (const pthread_condattr_t *)0p);  // workaround trac#208: cast should not be required
    133133                val = 0;
    134134        }
     
    219219                }
    220220        }
     221
     222        // Semaphore which only supports a single thread and one post
     223        // Semaphore which only supports a single thread
     224        struct oneshot {
     225                struct $thread * volatile ptr;
     226        };
     227
     228        static inline {
     229                void  ?{}(oneshot & this) {
     230                        this.ptr = 0p;
     231                }
     232
     233                void ^?{}(oneshot & this) {}
     234
     235                bool wait(oneshot & this) {
     236                        for() {
     237                                struct $thread * expected = this.ptr;
     238                                if(expected == 1p) return false;
     239                                /* paranoid */ verify( expected == 0p );
     240                                if(__atomic_compare_exchange_n(&this.ptr, &expected, active_thread(), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
     241                                        park( __cfaabi_dbg_ctx );
     242                                        /* paranoid */ verify( this.ptr == 1p );
     243                                        return true;
     244                                }
     245                        }
     246                }
     247
     248                bool post(oneshot & this) {
     249                        struct $thread * got = __atomic_exchange_n( &this.ptr, 1p, __ATOMIC_SEQ_CST);
     250                        if( got == 0p ) return false;
     251                        unpark( got __cfaabi_dbg_ctx2 );
     252                        return true;
     253                }
     254        }
    221255#endif
Note: See TracChangeset for help on using the changeset viewer.