Changes in benchmark/readyQ/rq_bench.hpp [e54d0c3:56ac392]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/readyQ/rq_bench.hpp
re54d0c3 r56ac392 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 } 8 14 9 15 enum { TIMEGRAN = 1000000000LL }; // nanosecond granularity, except for timeval … … 75 81 } 76 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 77 131 // ========================================================================================== 78 132 #include <cstdlib> … … 188 242 this->help = help; 189 243 this->variable = reinterpret_cast<void*>(&variable); 190 this->parse_fun = reinterpret_cast<bool (*)(const char *, void * )>(static_cast<bool (*)(const char *, T & )>(parse)); 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 191 248 } 192 249 … … 197 254 this->help = help; 198 255 this->variable = reinterpret_cast<void*>(&variable); 199 this->parse_fun = reinterpret_cast<bool (*)(const char *, void * )>(parse); 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 200 260 } 201 261 };
Note: See TracChangeset
for help on using the changeset viewer.