feat/support_fiber #2

Merged
tqcq merged 57 commits from feat/support_fiber into master 2024-06-21 10:33:52 +08:00
4 changed files with 19 additions and 11 deletions
Showing only changes of commit 7306461b2f - Show all commits

View File

@ -90,7 +90,8 @@ void CoarseClockInitializer::Start() {
while (running_.load(std::memory_order_relaxed)) {
// std::this_thread::sleep_for(std::chrono::nanoseconds(500));
UpdateCoarseTimestamps();
Sleep(accuracy_as_ns / 2);
// Sleep(accuracy_as_ns / 2);
std::this_thread::sleep_for(kAccuracy / 2);
}
});
}

View File

@ -17,7 +17,7 @@ namespace chrono {
class CoarseClockInitializer {
public:
static constexpr auto kAccuracy = std::chrono::microseconds(100);
static constexpr auto kAccuracy = std::chrono::microseconds(500);
static CoarseClockInitializer *Instance();
// for `tile::Start()`

View File

@ -4,7 +4,7 @@
namespace tile {
static constexpr auto one = detail::chrono::CoarseClockInitializer::kAccuracy;
static constexpr auto one_ms = std::chrono::milliseconds(1);
long AvageTime(std::function<long()> f, std::size_t n = 100) {
long double total = 0;
@ -17,28 +17,30 @@ long AvageTime(std::function<long()> f, std::size_t n = 100) {
TEST(SystemClock, Compare) {
auto diff = AvageTime([] {
return (ReadSystemClock() - std::chrono::system_clock::now()) / one;
return (ReadSystemClock() - std::chrono::system_clock::now()) / one_ms;
});
ASSERT_NEAR(diff, 0, 5);
}
TEST(SteadyClock, Compare) {
auto diff = AvageTime([] {
return (ReadSteadyClock() - std::chrono::steady_clock::now()) / one;
return (ReadSteadyClock() - std::chrono::steady_clock::now()) / one_ms;
});
ASSERT_NEAR(diff, 0, 5);
}
TEST(CoarseSystemClock, Compare) {
auto diff = AvageTime([] {
return (ReadCoarseSystemClock() - std::chrono::system_clock::now()) / one;
return (ReadCoarseSystemClock() - std::chrono::system_clock::now()) /
one_ms;
});
ASSERT_NEAR(diff, 0, 50);
}
TEST(CoarseSteadyClock, Compare) {
auto diff = AvageTime([] {
return (ReadCoarseSteadyClock() - std::chrono::steady_clock::now()) / one;
return (ReadCoarseSteadyClock() - std::chrono::steady_clock::now()) /
one_ms;
});
ASSERT_NEAR(diff, 0, 50);
}

View File

@ -61,6 +61,7 @@ static void BusySleep(std::chrono::duration<Rep, Period> dur) {
namespace object_pool {
TEST(ThreadLocalPool, All) {
auto start = ReadCoarseSteadyClock();
// create 1000 unref objects;
ASSERT_EQ(alive, 0);
{
@ -76,13 +77,17 @@ TEST(ThreadLocalPool, All) {
BusySleep(std::chrono::milliseconds(10));
Get<C>().Reset(); // Trigger wash out if possible.
}
ASSERT_EQ(PoolTraits<C>::kHighWaterMark + PoolTraits<C>::kLowWaterMark,
alive); // High-water mark.
if ((ReadCoarseSteadyClock() - start) < PoolTraits<C>::kMaxIdle) {
ASSERT_EQ(PoolTraits<C>::kHighWaterMark + PoolTraits<C>::kLowWaterMark,
alive); // High-water mark.
}
// Max idle not reached. No effect.
Get<C>().Reset();
ASSERT_EQ(PoolTraits<C>::kHighWaterMark + PoolTraits<C>::kLowWaterMark,
alive);
if ((ReadCoarseSteadyClock() - start) < PoolTraits<C>::kMaxIdle) {
ASSERT_EQ(PoolTraits<C>::kHighWaterMark + PoolTraits<C>::kLowWaterMark,
alive);
}
BusySleep(std::chrono::milliseconds(5000));
// std::this_thread::sleep_for(std::chrono::milliseconds(5000));