From bb4d159218eb5fb6603f0c82702800c7bd4dae90 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Fri, 1 Nov 2024 10:38:54 -0500 Subject: [PATCH] GH-985 Remove duplicate code --- libraries/chain/platform_timer_asio_fallback.cpp | 14 +------------- libraries/chain/platform_timer_kqueue.cpp | 5 +---- libraries/chain/platform_timer_posix.cpp | 5 +---- 3 files changed, 3 insertions(+), 21 deletions(-) diff --git a/libraries/chain/platform_timer_asio_fallback.cpp b/libraries/chain/platform_timer_asio_fallback.cpp index b82552e412..547bc5dcc7 100644 --- a/libraries/chain/platform_timer_asio_fallback.cpp +++ b/libraries/chain/platform_timer_asio_fallback.cpp @@ -64,24 +64,12 @@ void platform_timer::start(fc::time_point tp) { if(x.count() <= 0) expired = true; else { -#if 0 - std::promise p; - auto f = p.get_future(); - checktime_ios->post([&p,this]() { - expired = false; - p.set_value(); - }); - f.get(); -#endif expired = false; my->timer->expires_after(std::chrono::microseconds(x.count())); my->timer->async_wait([this](const boost::system::error_code& ec) { if(ec) return; - bool expected = false; - if (expired.compare_exchange_strong(expected, true)) { - call_expiration_callback(); - } + expire_now(); }); } } diff --git a/libraries/chain/platform_timer_kqueue.cpp b/libraries/chain/platform_timer_kqueue.cpp index 823428c804..16f076a0cb 100644 --- a/libraries/chain/platform_timer_kqueue.cpp +++ b/libraries/chain/platform_timer_kqueue.cpp @@ -58,10 +58,7 @@ platform_timer::platform_timer() { if(c == 1 && anEvent.filter == EVFILT_TIMER) { platform_timer* self = (platform_timer*)anEvent.udata; - bool expected = false; - if (self->expired.compare_exchange_strong(expected, true)) { - self->call_expiration_callback(); - } + self->expire_now(); } else if(c == 1 && anEvent.filter == EVFILT_USER) return; diff --git a/libraries/chain/platform_timer_posix.cpp b/libraries/chain/platform_timer_posix.cpp index 3702333c32..4388fa18b9 100644 --- a/libraries/chain/platform_timer_posix.cpp +++ b/libraries/chain/platform_timer_posix.cpp @@ -21,10 +21,7 @@ struct platform_timer::impl { static void sig_handler(int, siginfo_t* si, void*) { platform_timer* self = (platform_timer*)si->si_value.sival_ptr; - bool expected = false; - if (self->expired.compare_exchange_strong(expected, true)) { - self->call_expiration_callback(); - } + self->expire_now(); } };