feat update chrono
Some checks failed
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (Debug) (push) Failing after 3m26s
linux-arm-gcc / linux-gcc-arm (Debug) (push) Failing after 3m57s
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (Release) (push) Successful in 5m39s
linux-arm-gcc / linux-gcc-arm (Release) (push) Successful in 5m45s
linux-arm-gcc / linux-gcc-armhf (Debug) (push) Failing after 2m40s
linux-mips-gcc / linux-gcc-mipsel (Debug) (push) Failing after 3m24s
linux-arm-gcc / linux-gcc-armhf (Release) (push) Successful in 5m9s
linux-mips64-gcc / linux-gcc-mips64el (Debug) (push) Failing after 3m27s
linux-mips-gcc / linux-gcc-mipsel (Release) (push) Successful in 4m59s
linux-riscv64-gcc / linux-gcc-riscv64 (Debug) (push) Failing after 2m51s
linux-x64-gcc / linux-gcc (Debug) (push) Failing after 3m12s
linux-mips64-gcc / linux-gcc-mips64el (Release) (push) Successful in 5m11s
linux-riscv64-gcc / linux-gcc-riscv64 (Release) (push) Successful in 5m8s
linux-x86-gcc / linux-gcc (Debug) (push) Failing after 55s
linux-x86-gcc / linux-gcc (Release) (push) Failing after 52s
linux-x64-gcc / linux-gcc (Release) (push) Successful in 4m24s

This commit is contained in:
tqcq 2024-06-17 10:15:38 +08:00
parent f9c0e90b06
commit 7306461b2f
4 changed files with 19 additions and 11 deletions

View File

@ -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);
} }
}); });
} }

View File

@ -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()`

View File

@ -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);
} }

View File

@ -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));