feat/support_fiber #2
@ -90,7 +90,8 @@ void CoarseClockInitializer::Start() {
|
|||||||
while (running_.load(std::memory_order_relaxed)) {
|
while (running_.load(std::memory_order_relaxed)) {
|
||||||
// std::this_thread::sleep_for(std::chrono::nanoseconds(500));
|
// std::this_thread::sleep_for(std::chrono::nanoseconds(500));
|
||||||
UpdateCoarseTimestamps();
|
UpdateCoarseTimestamps();
|
||||||
Sleep(accuracy_as_ns / 2);
|
// Sleep(accuracy_as_ns / 2);
|
||||||
|
std::this_thread::sleep_for(kAccuracy / 2);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ namespace chrono {
|
|||||||
|
|
||||||
class CoarseClockInitializer {
|
class CoarseClockInitializer {
|
||||||
public:
|
public:
|
||||||
static constexpr auto kAccuracy = std::chrono::microseconds(100);
|
static constexpr auto kAccuracy = std::chrono::microseconds(500);
|
||||||
static CoarseClockInitializer *Instance();
|
static CoarseClockInitializer *Instance();
|
||||||
|
|
||||||
// for `tile::Start()`
|
// for `tile::Start()`
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
namespace tile {
|
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 AvageTime(std::function<long()> f, std::size_t n = 100) {
|
||||||
long double total = 0;
|
long double total = 0;
|
||||||
@ -17,28 +17,30 @@ long AvageTime(std::function<long()> f, std::size_t n = 100) {
|
|||||||
|
|
||||||
TEST(SystemClock, Compare) {
|
TEST(SystemClock, Compare) {
|
||||||
auto diff = AvageTime([] {
|
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);
|
ASSERT_NEAR(diff, 0, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(SteadyClock, Compare) {
|
TEST(SteadyClock, Compare) {
|
||||||
auto diff = AvageTime([] {
|
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);
|
ASSERT_NEAR(diff, 0, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(CoarseSystemClock, Compare) {
|
TEST(CoarseSystemClock, Compare) {
|
||||||
auto diff = AvageTime([] {
|
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);
|
ASSERT_NEAR(diff, 0, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(CoarseSteadyClock, Compare) {
|
TEST(CoarseSteadyClock, Compare) {
|
||||||
auto diff = AvageTime([] {
|
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);
|
ASSERT_NEAR(diff, 0, 50);
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,7 @@ static void BusySleep(std::chrono::duration<Rep, Period> dur) {
|
|||||||
namespace object_pool {
|
namespace object_pool {
|
||||||
|
|
||||||
TEST(ThreadLocalPool, All) {
|
TEST(ThreadLocalPool, All) {
|
||||||
|
auto start = ReadCoarseSteadyClock();
|
||||||
// create 1000 unref objects;
|
// create 1000 unref objects;
|
||||||
ASSERT_EQ(alive, 0);
|
ASSERT_EQ(alive, 0);
|
||||||
{
|
{
|
||||||
@ -76,13 +77,17 @@ TEST(ThreadLocalPool, All) {
|
|||||||
BusySleep(std::chrono::milliseconds(10));
|
BusySleep(std::chrono::milliseconds(10));
|
||||||
Get<C>().Reset(); // Trigger wash out if possible.
|
Get<C>().Reset(); // Trigger wash out if possible.
|
||||||
}
|
}
|
||||||
ASSERT_EQ(PoolTraits<C>::kHighWaterMark + PoolTraits<C>::kLowWaterMark,
|
if ((ReadCoarseSteadyClock() - start) < PoolTraits<C>::kMaxIdle) {
|
||||||
alive); // High-water mark.
|
ASSERT_EQ(PoolTraits<C>::kHighWaterMark + PoolTraits<C>::kLowWaterMark,
|
||||||
|
alive); // High-water mark.
|
||||||
|
}
|
||||||
|
|
||||||
// Max idle not reached. No effect.
|
// Max idle not reached. No effect.
|
||||||
Get<C>().Reset();
|
Get<C>().Reset();
|
||||||
ASSERT_EQ(PoolTraits<C>::kHighWaterMark + PoolTraits<C>::kLowWaterMark,
|
if ((ReadCoarseSteadyClock() - start) < PoolTraits<C>::kMaxIdle) {
|
||||||
alive);
|
ASSERT_EQ(PoolTraits<C>::kHighWaterMark + PoolTraits<C>::kLowWaterMark,
|
||||||
|
alive);
|
||||||
|
}
|
||||||
|
|
||||||
BusySleep(std::chrono::milliseconds(5000));
|
BusySleep(std::chrono::milliseconds(5000));
|
||||||
// std::this_thread::sleep_for(std::chrono::milliseconds(5000));
|
// std::this_thread::sleep_for(std::chrono::milliseconds(5000));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user