Changes in benchmark/readyQ/rq_bench.hpp [56ac392:c4241b6]
- File:
-
- 1 edited
-
benchmark/readyQ/rq_bench.hpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
benchmark/readyQ/rq_bench.hpp
r56ac392 rc4241b6 6 6 #include <time.h> // timespec 7 7 #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 }14 8 15 9 enum { TIMEGRAN = 1000000000LL }; // nanosecond granularity, except for timeval … … 52 46 } 53 47 54 uint64_t timeHiRes() {48 uint64_t getTimeNsec() { 55 49 timespec curr; 56 50 clock_gettime( CLOCK_REALTIME, &curr ); … … 66 60 for(;;) { 67 61 Sleeper::usleep(100000); 68 uint64_t end = timeHiRes();62 uint64_t end = getTimeNsec(); 69 63 uint64_t delta = end - start; 70 64 if(is_tty) { … … 80 74 } 81 75 } 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 };130 76 131 77 // ========================================================================================== … … 242 188 this->help = help; 243 189 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)); 248 191 } 249 192 … … 254 197 this->help = help; 255 198 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); 260 200 } 261 201 };
Note:
See TracChangeset
for help on using the changeset viewer.