fix use busy sleep
Some checks are pending
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (Debug) (push) Waiting to run
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (Release) (push) Waiting to run
linux-arm-gcc / linux-gcc-arm (Debug) (push) Waiting to run
linux-arm-gcc / linux-gcc-arm (Release) (push) Waiting to run
linux-arm-gcc / linux-gcc-armhf (Debug) (push) Waiting to run
linux-arm-gcc / linux-gcc-armhf (Release) (push) Waiting to run
linux-mips-gcc / linux-gcc-mipsel (Debug) (push) Waiting to run
linux-mips-gcc / linux-gcc-mipsel (Release) (push) Waiting to run
linux-mips64-gcc / linux-gcc-mips64el (Debug) (push) Waiting to run
linux-mips64-gcc / linux-gcc-mips64el (Release) (push) Waiting to run
linux-riscv64-gcc / linux-gcc-riscv64 (Debug) (push) Waiting to run
linux-riscv64-gcc / linux-gcc-riscv64 (Release) (push) Waiting to run
linux-x64-gcc / linux-gcc (Debug) (push) Waiting to run
linux-x64-gcc / linux-gcc (Release) (push) Waiting to run
linux-x86-gcc / linux-gcc (Debug) (push) Waiting to run
linux-x86-gcc / linux-gcc (Release) (push) Waiting to run
Some checks are pending
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (Debug) (push) Waiting to run
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (Release) (push) Waiting to run
linux-arm-gcc / linux-gcc-arm (Debug) (push) Waiting to run
linux-arm-gcc / linux-gcc-arm (Release) (push) Waiting to run
linux-arm-gcc / linux-gcc-armhf (Debug) (push) Waiting to run
linux-arm-gcc / linux-gcc-armhf (Release) (push) Waiting to run
linux-mips-gcc / linux-gcc-mipsel (Debug) (push) Waiting to run
linux-mips-gcc / linux-gcc-mipsel (Release) (push) Waiting to run
linux-mips64-gcc / linux-gcc-mips64el (Debug) (push) Waiting to run
linux-mips64-gcc / linux-gcc-mips64el (Release) (push) Waiting to run
linux-riscv64-gcc / linux-gcc-riscv64 (Debug) (push) Waiting to run
linux-riscv64-gcc / linux-gcc-riscv64 (Release) (push) Waiting to run
linux-x64-gcc / linux-gcc (Debug) (push) Waiting to run
linux-x64-gcc / linux-gcc (Release) (push) Waiting to run
linux-x86-gcc / linux-gcc (Debug) (push) Waiting to run
linux-x86-gcc / linux-gcc (Release) (push) Waiting to run
This commit is contained in:
parent
4d79500d07
commit
13f2838375
@ -1,5 +1,7 @@
|
||||
#include "tile/base/object_pool.h"
|
||||
|
||||
#include "tile/base/thread/spinlock.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <thread>
|
||||
@ -48,6 +50,14 @@ constexpr std::size_t PoolTraits<D>::kLowWaterMark;
|
||||
constexpr std::size_t PoolTraits<D>::kHighWaterMark;
|
||||
constexpr std::chrono::milliseconds PoolTraits<D>::kMaxIdle;
|
||||
|
||||
template <typename Rep, typename Period>
|
||||
static void BusySleep(std::chrono::duration<Rep, Period> dur) {
|
||||
auto end = ReadCoarseSteadyClock() + dur;
|
||||
while (ReadCoarseSteadyClock() < end) {
|
||||
RelaxCpu();
|
||||
}
|
||||
}
|
||||
|
||||
namespace object_pool {
|
||||
|
||||
TEST(ThreadLocalPool, All) {
|
||||
@ -62,7 +72,8 @@ TEST(ThreadLocalPool, All) {
|
||||
ptrs.clear();
|
||||
}
|
||||
for (int i = 0; i != 200; ++i) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
// std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
BusySleep(std::chrono::milliseconds(10));
|
||||
Get<C>().Reset(); // Trigger wash out if possible.
|
||||
}
|
||||
ASSERT_EQ(PoolTraits<C>::kHighWaterMark + PoolTraits<C>::kLowWaterMark,
|
||||
@ -73,13 +84,15 @@ TEST(ThreadLocalPool, All) {
|
||||
ASSERT_EQ(PoolTraits<C>::kHighWaterMark + PoolTraits<C>::kLowWaterMark,
|
||||
alive);
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
|
||||
BusySleep(std::chrono::milliseconds(5000));
|
||||
// std::this_thread::sleep_for(std::chrono::milliseconds(5000));
|
||||
for (int i = 0; i != 100; ++i) {
|
||||
Get<C>().Reset(); // We have a limit on objects to loop per call. So we may
|
||||
// need several calls to lower alive objects to low-water
|
||||
// mark.
|
||||
std::this_thread::sleep_for(
|
||||
std::chrono::milliseconds(10)); // The limit on wash interval..
|
||||
BusySleep(std::chrono::milliseconds(10));
|
||||
// std::this_thread::sleep_for(
|
||||
// std::chrono::milliseconds(10)); // The limit on wash interval..
|
||||
}
|
||||
// Low-water mark. + 1 for the object just freed (as it's fresh and won't be
|
||||
// affected by low-water mark.).
|
||||
|
@ -9,7 +9,7 @@
|
||||
// aarch64 isb
|
||||
// arm v6 yield
|
||||
|
||||
#if defined(__x86_64__)
|
||||
#if defined(__x86_64__) || defined(__i386__)
|
||||
#define TILE_CPU_RELAX() asm volatile("pause" ::: "memory")
|
||||
#elif defined(__aarch64__)
|
||||
#define TILE_CPU_RELAX() asm volatile("isb" ::)
|
||||
@ -30,4 +30,5 @@ void Spinlock::LockSlow() noexcept {
|
||||
} while (locked_.exchange(true, std::memory_order_acquire));
|
||||
}
|
||||
|
||||
void RelaxCpu() noexcept { TILE_CPU_RELAX(); }
|
||||
} // namespace tile
|
||||
|
@ -29,6 +29,8 @@ private:
|
||||
private:
|
||||
std::atomic<bool> locked_{false};
|
||||
};
|
||||
|
||||
void RelaxCpu() noexcept;
|
||||
} // namespace tile
|
||||
|
||||
#endif // TILE_BASE_THREAD_SPINLOCK_H
|
||||
|
Loading…
Reference in New Issue
Block a user