26 template <
typename Integer>
27 void run_atomic_wait_basic() {
28 auto&& atomic = std::atomic<Integer>{0};
30 auto&& one = std::thread{[&]() {
33 if (atomic.load() == 1) {
45 template <
typename Integer>
46 void run_atomic_wait_until_with_timeout() {
47 auto&& atomic = std::atomic<Integer>{0};
49 auto&& one = std::thread{[&]() {
58 if (result == std::cv_status::timeout) {
68 template <
typename Integer>
69 void run_atomic_wait_until_with_notification() {
70 auto&& atomic = std::atomic<Integer>{0};
72 auto&& one = std::thread{[&]() {
98 auto lck = std::unique_lock<std::mutex>{
mutex_};
107 auto lck = std::unique_lock<std::mutex>{
mutex_};
112 auto lck = std::unique_lock<std::mutex>{
mutex_};
119 std::condition_variable
cv_;
123 template <
typename Integer>
124 void run_atomic_aliasing() {
126 auto&& one = SimpleBaton{};
127 auto&& two = SimpleBaton{};
129 auto threadOne = std::thread{[&]() {
133 if (atomic->load() == 1) {
147 auto threadTwo = std::thread{[&]() {
152 while (!two.try_wait()) {
161 run_atomic_wait_basic<std::uint32_t>();
164 TEST(AtomicWait, BasicNonStandardWidths) {
165 run_atomic_wait_basic<std::uint8_t>();
166 run_atomic_wait_basic<std::uint16_t>();
167 run_atomic_wait_basic<std::uint64_t>();
170 TEST(AtomicWait, AtomicWaitUntilTimeout) {
171 run_atomic_wait_until_with_timeout<std::uint32_t>();
174 TEST(AtomicWait, AtomicWaitUntilTimeoutNonStandardWidths) {
175 run_atomic_wait_until_with_timeout<std::uint8_t>();
176 run_atomic_wait_until_with_timeout<std::uint16_t>();
177 run_atomic_wait_until_with_timeout<std::uint64_t>();
180 TEST(AtomicWait, AtomicWaitUntilNotified) {
181 run_atomic_wait_until_with_notification<std::uint32_t>();
184 TEST(AtomicWait, AtomicWaitUntilNotifiedNonStandardWidths) {
185 run_atomic_wait_until_with_notification<std::uint8_t>();
186 run_atomic_wait_until_with_notification<std::uint16_t>();
187 run_atomic_wait_until_with_notification<std::uint64_t>();
190 TEST(AtomicWait, AtomicWaitAliasing) {
191 run_atomic_aliasing<std::uint32_t>();
194 TEST(AtomicWait, AtomicWaitAliasingNonStandardWidths) {
195 run_atomic_aliasing<std::uint8_t>();
196 run_atomic_aliasing<std::uint16_t>();
197 run_atomic_aliasing<std::uint64_t>();
#define EXPECT_EQ(val1, val2)
std::chrono::steady_clock::time_point now()
—— Concurrent Priority Queue Implementation ——
in_place_tag in_place(in_place_tag={})
std::condition_variable cv_
bool wait(Waiter *waiter, bool shouldSleep, Waiter *&next)
TEST(AtomicWait, AtomicWaitAliasingNonStandardWidths)
void atomic_wait(const std::atomic< Integer > *atomic, Integer expected)
#define EXPECT_TRUE(condition)
void atomic_notify_one(const std::atomic< Integer > *atomic)
std::cv_status atomic_wait_until(const std::atomic< Integer > *atomic, Integer expected, const std::chrono::time_point< Clock, Duration > &deadline)