Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/readyQ/cycle.cpp

    rc4241b6 r56ac392  
    33#include <libfibre/fibre.h>
    44
    5 class __attribute__((aligned(128))) bench_sem {
    6         Fibre * volatile ptr = nullptr;
    7 public:
    8         inline bool wait() {
    9                 static Fibre * const ready  = reinterpret_cast<Fibre * const>(1ull);
    10                 for(;;) {
    11                         Fibre * expected = this->ptr;
    12                         if(expected == ready) {
    13                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, nullptr, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    14                                         return false;
    15                                 }
    16                         }
    17                         else {
    18                                 /* paranoid */ assert( expected == nullptr );
    19                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, fibre_self(), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    20                                         fibre_park();
    21                                         return true;
    22                                 }
    23                         }
    24 
    25                 }
    26         }
    27 
    28         inline bool post() {
    29                 static Fibre * const ready  = reinterpret_cast<Fibre * const>(1ull);
    30                 for(;;) {
    31                         Fibre * expected = this->ptr;
    32                         if(expected == ready) return false;
    33                         if(expected == nullptr) {
    34                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, ready, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    35                                         return false;
    36                                 }
    37                         }
    38                         else {
    39                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, nullptr, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    40                                         fibre_unpark( expected );
    41                                         return true;
    42                                 }
    43                         }
    44                 }
    45         }
    46 };
    475struct Partner {
    486        unsigned long long count  = 0;
     
    9351
    9452                        bool is_tty = isatty(STDOUT_FILENO);
    95                         start = getTimeNsec();
     53                        start = timeHiRes();
    9654
    9755                        for(int i = 0; i < nthreads; i++) {
     
    10159
    10260                        stop = true;
    103                         end = getTimeNsec();
     61                        end = timeHiRes();
    10462                        printf("\nDone\n");
    10563
Note: See TracChangeset for help on using the changeset viewer.