Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/readyQ/locality.cpp

    r56ac392 rf03209d3  
    99        uint64_t dmigs = 0;
    1010        uint64_t gmigs = 0;
     11};
     12
     13class __attribute__((aligned(128))) bench_sem {
     14        Fibre * volatile ptr = nullptr;
     15public:
     16        inline bool wait() {
     17                static Fibre * const ready  = reinterpret_cast<Fibre * const>(1ull);
     18                for(;;) {
     19                        Fibre * expected = this->ptr;
     20                        if(expected == ready) {
     21                                if(__atomic_compare_exchange_n(&this->ptr, &expected, nullptr, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
     22                                        return false;
     23                                }
     24                        }
     25                        else {
     26                                /* paranoid */ assert( expected == nullptr );
     27                                if(__atomic_compare_exchange_n(&this->ptr, &expected, fibre_self(), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
     28                                        fibre_park();
     29                                        return true;
     30                                }
     31                        }
     32
     33                }
     34        }
     35
     36        inline bool post() {
     37                static Fibre * const ready  = reinterpret_cast<Fibre * const>(1ull);
     38                for(;;) {
     39                        Fibre * expected = this->ptr;
     40                        if(expected == ready) return false;
     41                        if(expected == nullptr) {
     42                                if(__atomic_compare_exchange_n(&this->ptr, &expected, ready, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
     43                                        return false;
     44                                }
     45                        }
     46                        else {
     47                                if(__atomic_compare_exchange_n(&this->ptr, &expected, nullptr, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
     48                                        fibre_unpark( expected );
     49                                        return true;
     50                                }
     51                        }
     52                }
     53        }
    1154};
    1255
     
    244287
    245288                        bool is_tty = isatty(STDOUT_FILENO);
    246                         start = timeHiRes();
     289                        start = getTimeNsec();
    247290
    248291                        for(size_t i = 0; i < nthreads; i++) {
     
    252295
    253296                        stop = true;
    254                         end = timeHiRes();
     297                        end = getTimeNsec();
    255298                        printf("\nDone\n");
    256299
Note: See TracChangeset for help on using the changeset viewer.