diff --git a/tile/fiber/detail/fiber_benchmark.cc b/tile/fiber/detail/fiber_benchmark.cc deleted file mode 100644 index 14f3fd4..0000000 --- a/tile/fiber/detail/fiber_benchmark.cc +++ /dev/null @@ -1,37 +0,0 @@ -#include "tile/fiber/detail/fiber.h" - -#include "tile/base/random.h" -#include "tile/base/string.h" - -#include "benchmark/benchmark.h" - -namespace tile { -namespace fiber { -namespace detail { -void Benchmark_FiberSwitch(benchmark::State &state) { - std::unique_ptr master_fiber; - - int switch_cnt = 0; - master_fiber = Fiber::Create([&] { - while (state.KeepRunning()) { - std::unique_ptr worker_fiber1 = - Fiber::Create([&] { ++switch_cnt; }); - - auto start = std::chrono::steady_clock::now(); - worker_fiber1->Resume(); - auto end = std::chrono::steady_clock::now(); - auto elapsed = std::chrono::duration_cast>( - end - start); - state.SetIterationTime(elapsed.count()); - } - }); - - master_fiber->Resume(); - state.counters["switch_cnt"] = switch_cnt; -} - -} // namespace detail -} // namespace fiber -} // namespace tile - -BENCHMARK(tile::fiber::detail::Benchmark_FiberSwitch)->UseManualTime(); diff --git a/tile/fiber/detail/fiber_test.cc b/tile/fiber/detail/fiber_test.cc deleted file mode 100644 index 2cf3c2d..0000000 --- a/tile/fiber/detail/fiber_test.cc +++ /dev/null @@ -1,52 +0,0 @@ -#include "tile/base/random.h" -#include "tile/fiber/detail/fiber.h" - -#include "gtest/gtest.h" -namespace tile { -namespace fiber { -namespace detail { - -TEST(Fiber, Base) { - constexpr auto kMaxCnt = 1; // 100 * 1000; - int cnt = 0; - int resume_cnt = 0; - - // 0 -> master fiber - // [1, 9] -> worker fibers - std::unique_ptr master_fiber; - - master_fiber = Fiber::Create([&] { - TILE_LOG_INFO("master fiber"); - // ASSERT_EQ(cnt, 0); - ASSERT_EQ(GetMasterFiber(), master_fiber.get()); - ASSERT_EQ(GetCurrentFiber(), master_fiber.get()); - - ASSERT_EQ(cnt, 0); - while (cnt < kMaxCnt) { - std::unique_ptr worker_fiber = Fiber::Create([&] { - while (cnt < kMaxCnt) { - ASSERT_EQ(GetCurrentFiber(), worker_fiber.get()); - ++cnt; - master_fiber->Resume(); - } - }); - - while (cnt < kMaxCnt) { - int old = cnt; - worker_fiber->Resume(); - ASSERT_EQ(old + 1, cnt); - ASSERT_EQ(GetCurrentFiber(), master_fiber.get()); - } - } - - ASSERT_EQ(cnt, kMaxCnt); - }); - - SetUpMasterFiber(master_fiber.get()); - SetUpCurrentFiber(nullptr); - master_fiber->Resume(); -} - -} // namespace detail -} // namespace fiber -} // namespace tile diff --git a/tile/fiber/this_fiber.h b/tile/fiber/this_fiber.h deleted file mode 100644 index ebecd8a..0000000 --- a/tile/fiber/this_fiber.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef TILE_FIBER_THIS_FIBER_H -#define TILE_FIBER_THIS_FIBER_H - -#pragma once - -#include "tile/base/chrono.h" -#include "tile/fiber/fiber.h" -#include - -namespace tile { -namespace this_fiber { - -Fiber::Id GetId(); - -void Yield(); - -void SleepUntil(std::chrono::steady_clock expires_at); - -void SleepFor(std::chrono::nanoseconds expires_in); - -template -void SleepUntil(const std::chrono::time_point &expires_at) { - return SleepUntil(ReadSteadyClock() + (expires_at - Clock::now())); -} - -template -void SleepFor(const std::chrono::duration &expires_in) { - return SleepFor( - std::chrono::duration_cast(expires_in)); -} - -} // namespace this_fiber -} // namespace tile - -#endif // TILE_FIBER_THIS_FIBER_H