Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/readyQ/rq_bench.hpp

    r56ac392 rc4241b6  
    66#include <time.h>                                                                               // timespec
    77#include <sys/time.h>                                                                   // timeval
    8 
    9 typedef __uint128_t __lehmer64_state_t;
    10 static inline uint64_t __lehmer64( __lehmer64_state_t & state ) {
    11         state *= 0xda942042e4dd58b5;
    12         return state >> 64;
    13 }
    148
    159enum { TIMEGRAN = 1000000000LL };                                       // nanosecond granularity, except for timeval
     
    5246        }
    5347
    54 uint64_t timeHiRes() {
     48uint64_t getTimeNsec() {
    5549        timespec curr;
    5650        clock_gettime( CLOCK_REALTIME, &curr );
     
    6660        for(;;) {
    6761                Sleeper::usleep(100000);
    68                 uint64_t end = timeHiRes();
     62                uint64_t end = getTimeNsec();
    6963                uint64_t delta = end - start;
    7064                if(is_tty) {
     
    8074        }
    8175}
    82 
    83 class Fibre;
    84 int fibre_park();
    85 int fibre_unpark( Fibre * );
    86 Fibre * fibre_self();
    87 
    88 class __attribute__((aligned(128))) bench_sem {
    89         Fibre * volatile ptr = nullptr;
    90 public:
    91         inline bool wait() {
    92                 static Fibre * const ready  = reinterpret_cast<Fibre *>(1ull);
    93                 for(;;) {
    94                         Fibre * expected = this->ptr;
    95                         if(expected == ready) {
    96                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, nullptr, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    97                                         return false;
    98                                 }
    99                         }
    100                         else {
    101                                 /* paranoid */ assert( expected == nullptr );
    102                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, fibre_self(), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    103                                         fibre_park();
    104                                         return true;
    105                                 }
    106                         }
    107 
    108                 }
    109         }
    110 
    111         inline bool post() {
    112                 static Fibre * const ready  = reinterpret_cast<Fibre *>(1ull);
    113                 for(;;) {
    114                         Fibre * expected = this->ptr;
    115                         if(expected == ready) return false;
    116                         if(expected == nullptr) {
    117                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, ready, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    118                                         return false;
    119                                 }
    120                         }
    121                         else {
    122                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, nullptr, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    123                                         fibre_unpark( expected );
    124                                         return true;
    125                                 }
    126                         }
    127                 }
    128         }
    129 };
    13076
    13177// ==========================================================================================
     
    242188                this->help       = help;
    243189                this->variable   = reinterpret_cast<void*>(&variable);
    244                 #pragma GCC diagnostic push
    245                 #pragma GCC diagnostic ignored "-Wcast-function-type"
    246                                 this->parse_fun  = reinterpret_cast<bool (*)(const char *, void * )>(static_cast<bool (*)(const char *, T & )>(parse));
    247                 #pragma GCC diagnostic pop
     190                this->parse_fun  = reinterpret_cast<bool (*)(const char *, void * )>(static_cast<bool (*)(const char *, T & )>(parse));
    248191        }
    249192
     
    254197                this->help       = help;
    255198                this->variable   = reinterpret_cast<void*>(&variable);
    256                 #pragma GCC diagnostic push
    257                 #pragma GCC diagnostic ignored "-Wcast-function-type"
    258                         this->parse_fun  = reinterpret_cast<bool (*)(const char *, void * )>(parse);
    259                 #pragma GCC diagnostic pop
     199                this->parse_fun  = reinterpret_cast<bool (*)(const char *, void * )>(parse);
    260200        }
    261201};
Note: See TracChangeset for help on using the changeset viewer.