src/benchmark/context.cpp
// Switches to the first context.
// Switches to the first context.
// Switches to the second context.
Switches to the first context.
Switches to the first context.
Switches to the second context.
Switches to the first context . Switches to the first context . Switches to the second context .
static void context_switch(benchmark::State& state) noexcept
{
  ice::context c0;
  ice::context c1;
  auto t0 = std::thread([&]() { c0.run(); });
  if (const auto ec = ice::set_thread_affinity(t0, 0)) {
    state.SkipWithError(ec.message().data());
  }
  auto t1 = std::thread([&]() { c1.run(); });
  if (const auto ec = ice::set_thread_affinity(t1, 1)) {
    state.SkipWithError(ec.message().data());
  }
  auto co = [&]() -> ice::sync<void> {
    auto i = 0;
    for (auto _ : state) {
      switch (i % 3) {
      case 0: [[fallthrough]];
      case 1: co_await ice::schedule(c0); break;
      case 2: co_await ice::schedule(c1); break;
      }
      i++;
    }
    c0.stop();
    c1.stop();
  }();
  t0.join();
  t1.join();
  co.get();
}
static void context_switch ( benchmark :: State & state ) noexcept { ice :: context c0 ; ice :: context c1 ; auto t0 = std :: thread ( [ & ] ( ) { c0 . run ( ) ; } ) ; if ( const auto ec = ice :: set_thread_affinity ( t0 , 0 ) ) { state . SkipWithError ( ec . message ( ) . data ( ) ) ; } auto t1 = std :: thread ( [ & ] ( ) { c1 . run ( ) ; } ) ; if ( const auto ec = ice :: set_thread_affinity ( t1 , 1 ) ) { state . SkipWithError ( ec . message ( ) . data ( ) ) ; } auto co = [ & ] ( ) -> ice :: sync < void > { auto i = 0 ; for ( auto _ : state ) { switch ( i % 3 ) { case 0 : [[ fallthrough ]] ; case 1 : co_await ice :: schedule ( c0 ) ; break ; case 2 : co_await ice :: schedule ( c1 ) ; break ; } i ++ ; } c0 . stop ( ) ; c1 . stop ( ) ; } ( ) ; t0 . join ( ) ; t1 . join ( ) ; co . get ( ) ; }
Switches to the first context.
Switches to the first context .