Changeset f9b2e73


Ignore:
Timestamp:
Nov 18, 2020, 4:51:39 PM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
7192145, 7f8fbe3
Parents:
7c9ac4a
Message:

Missed file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/readyQ/rq_bench.hpp

    r7c9ac4a rf9b2e73  
    11#include <cassert>
     2#include <climits>
     3#include <cstdint>
     4#include <cstdio>
    25
    36#include <time.h>                                                                               // timespec
     
    58
    69enum { TIMEGRAN = 1000000000LL };                                       // nanosecond granularity, except for timeval
    7 
    8 
    9 #include <libfibre/fibre.h>
    10 
    1110
    1211
     
    5756uint64_t from_fseconds(double sec) { return sec * TIMEGRAN; }
    5857
     58template<typename Sleeper>
    5959void wait(const uint64_t & start, bool is_tty) {
    6060        for(;;) {
    61                 Fibre::usleep(100000);
     61                Sleeper::usleep(100000);
    6262                uint64_t end = getTimeNsec();
    6363                uint64_t delta = end - start;
     
    7575}
    7676
    77 class __attribute__((aligned(128))) bench_sem {
    78         Fibre * volatile ptr = nullptr;
    79 public:
    80         inline bool wait() {
    81                 static Fibre * const ready  = reinterpret_cast<Fibre * const>(1ull);
    82                 for(;;) {
    83                         Fibre * expected = this->ptr;
    84                         if(expected == ready) {
    85                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, nullptr, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    86                                         return false;
    87                                 }
    88                         }
    89                         else {
    90                                 /* paranoid */ assert( expected == nullptr );
    91                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, fibre_self(), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    92                                         fibre_park();
    93                                         return true;
    94                                 }
    95                         }
    96 
    97                 }
    98         }
    99 
    100         inline bool post() {
    101                 static Fibre * const ready  = reinterpret_cast<Fibre * const>(1ull);
    102                 for(;;) {
    103                         Fibre * expected = this->ptr;
    104                         if(expected == ready) return false;
    105                         if(expected == nullptr) {
    106                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, ready, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    107                                         return false;
    108                                 }
    109                         }
    110                         else {
    111                                 if(__atomic_compare_exchange_n(&this->ptr, &expected, nullptr, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    112                                         fibre_unpark( expected );
    113                                         return true;
    114                                 }
    115                         }
    116                 }
    117         }
    118 };
    119 
    12077// ==========================================================================================
     78#include <cstdlib>
    12179#include <cstring>
     80
     81#include <algorithm>
    12282
    12383//-----------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.