diff --git a/internal/platform/implementation/apple/Tests/GNCTimerTest.mm b/internal/platform/implementation/apple/Tests/GNCTimerTest.mm index 74b9773f..269bdf0f 100644 --- a/internal/platform/implementation/apple/Tests/GNCTimerTest.mm +++ b/internal/platform/implementation/apple/Tests/GNCTimerTest.mm @@ -103,22 +103,4 @@ XCTAssertTrue(timer->Stop()); } -- (void)testFireNow { - XCTestExpectation* expectation = [self expectationWithDescription:@"Timer fired"]; - auto timer = std::make_unique(); - - bool fired = false; - XCTAssertTrue(timer->Create(1000, 0, [&]() { - dispatch_async(dispatch_get_main_queue(), ^{ - fired = true; - [expectation fulfill]; - }); - })); - - XCTAssertTrue(timer->FireNow()); - - [self waitForExpectationsWithTimeout:1.0 handler:nil]; - XCTAssertTrue(fired); -} - @end diff --git a/internal/platform/implementation/apple/timer.h b/internal/platform/implementation/apple/timer.h index b1fce6bc..9ef92c23 100644 --- a/internal/platform/implementation/apple/timer.h +++ b/internal/platform/implementation/apple/timer.h @@ -37,8 +37,6 @@ class Timer : public api::Timer { bool Stop() override ABSL_LOCKS_EXCLUDED(mutex_); - bool FireNow() override ABSL_LOCKS_EXCLUDED(mutex_); - private: absl::Mutex mutex_; absl::CondVar condvar_ ABSL_GUARDED_BY(mutex_); diff --git a/internal/platform/implementation/apple/timer.mm b/internal/platform/implementation/apple/timer.mm index 67dd4c3d..8b714520 100644 --- a/internal/platform/implementation/apple/timer.mm +++ b/internal/platform/implementation/apple/timer.mm @@ -106,32 +106,5 @@ bool Timer::Stop() { return true; } -bool Timer::FireNow() { - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) { - absl::AnyInvocable callback_to_run; - { - absl::MutexLock lock(&mutex_); - - // Don't fire if there's no callback or if a callback is already in progress. - if (!callback_ || callback_running_) { - return; - } - callback_running_ = true; - callback_to_run = std::move(callback_); - } - - // Execute callback outside of the lock. - callback_to_run(); - { - absl::MutexLock lock(&mutex_); - callback_ = std::move(callback_to_run); - callback_running_ = false; - condvar_.Signal(); // Notify Stop() if it's waiting. - } - }); - - return true; -} - } // namespace apple } // namespace nearby diff --git a/internal/platform/implementation/g3/timer.h b/internal/platform/implementation/g3/timer.h index 21c570dc..0a254ad7 100644 --- a/internal/platform/implementation/g3/timer.h +++ b/internal/platform/implementation/g3/timer.h @@ -54,14 +54,6 @@ class Timer : public api::Timer { return false; } - bool FireNow() override { - if (is_stopped_) { - return false; - } - callback_(); - return true; - } - private: bool Schedule(absl::Duration delay) { absl::MutexLock lock(&mutex_); diff --git a/internal/platform/implementation/timer.h b/internal/platform/implementation/timer.h index f265cd3f..abe87b71 100644 --- a/internal/platform/implementation/timer.h +++ b/internal/platform/implementation/timer.h @@ -39,7 +39,6 @@ class Timer { // Stops timer. No timer signal is sent after the call. virtual bool Stop() = 0; - virtual bool FireNow() = 0; }; } // namespace api diff --git a/internal/platform/implementation/windows/timer.cc b/internal/platform/implementation/windows/timer.cc index 0042a401..304c6571 100644 --- a/internal/platform/implementation/windows/timer.cc +++ b/internal/platform/implementation/windows/timer.cc @@ -22,7 +22,6 @@ #include "absl/synchronization/mutex.h" #include "absl/time/time.h" #include "internal/platform/logging.h" -#include "internal/platform/runnable.h" namespace nearby { namespace windows { @@ -63,27 +62,5 @@ bool Timer::Stop() { return result; } -bool Timer::FireNow() { - absl::MutexLock lock(&mutex_); - - if (!callback_) { - LOG(ERROR) << "callback_ is empty"; - return false; - } - - if (task_executor_ == nullptr) { - task_executor_ = std::make_unique(); - } - - if (task_executor_ == nullptr) { - LOG(ERROR) << "Failed to fire the task due to cannot create executor."; - return false; - } - - task_executor_->Execute([&]() { callback_(); }); - - return true; -} - } // namespace windows } // namespace nearby diff --git a/internal/platform/implementation/windows/timer.h b/internal/platform/implementation/windows/timer.h index 56acd562..b4a53869 100644 --- a/internal/platform/implementation/windows/timer.h +++ b/internal/platform/implementation/windows/timer.h @@ -24,7 +24,6 @@ #include "absl/synchronization/mutex.h" #include "internal/platform/implementation/cancelable.h" #include "internal/platform/implementation/timer.h" -#include "internal/platform/implementation/windows/submittable_executor.h" #include "internal/platform/implementation/windows/task_scheduler.h" namespace nearby { @@ -39,13 +38,10 @@ class Timer : public api::Timer { absl::AnyInvocable callback) override ABSL_LOCKS_EXCLUDED(mutex_); bool Stop() override ABSL_LOCKS_EXCLUDED(mutex_); - bool FireNow() override ABSL_LOCKS_EXCLUDED(mutex_); private: mutable absl::Mutex mutex_; absl::AnyInvocable callback_; - std::unique_ptr task_executor_ ABSL_GUARDED_BY(mutex_) = - nullptr; TaskScheduler task_scheduler_ ABSL_GUARDED_BY(mutex_); std::shared_ptr cancelable_task_ ABSL_GUARDED_BY(mutex_) = nullptr; diff --git a/internal/platform/implementation/windows/timer_test.cc b/internal/platform/implementation/windows/timer_test.cc index 0666ade1..f1a61597 100644 --- a/internal/platform/implementation/windows/timer_test.cc +++ b/internal/platform/implementation/windows/timer_test.cc @@ -55,24 +55,6 @@ TEST(TimerTest, TestRepeatTimer) { EXPECT_TRUE(timer->Stop()); } -TEST(TimerTest, TestFireNow) { - int count = 0; - absl::Notification notification; - - auto timer = nearby::api::ImplementationPlatform::CreateTimer(); - - EXPECT_TRUE(timer != nullptr); - EXPECT_TRUE(timer->Create(3000, 3000, [&count, ¬ification]() { - ++count; - notification.Notify(); - })); - EXPECT_TRUE(timer->FireNow()); - EXPECT_TRUE(timer->Stop()); - EXPECT_TRUE( - notification.WaitForNotificationWithTimeout(absl::Milliseconds(1000))); - EXPECT_EQ(count, 1); -} - } // namespace } // namespace windows } // namespace nearby diff --git a/internal/platform/timer.h b/internal/platform/timer.h index f085e412..89ac0f33 100644 --- a/internal/platform/timer.h +++ b/internal/platform/timer.h @@ -38,7 +38,6 @@ class Timer { absl::AnyInvocable callback) = 0; virtual void Stop() = 0; virtual bool IsRunning() = 0; - virtual bool FireNow() = 0; }; } // namespace nearby diff --git a/internal/platform/timer_impl.cc b/internal/platform/timer_impl.cc index e0f52fc7..bd9c8159 100644 --- a/internal/platform/timer_impl.cc +++ b/internal/platform/timer_impl.cc @@ -55,12 +55,4 @@ void TimerImpl::Stop() { bool TimerImpl::IsRunning() { return (internal_timer_ != nullptr); } -bool TimerImpl::FireNow() { - if (IsRunning()) { - return internal_timer_->FireNow(); - } - - return false; -} - } // namespace nearby diff --git a/internal/platform/timer_impl.h b/internal/platform/timer_impl.h index 9e1c268e..a918fcd8 100644 --- a/internal/platform/timer_impl.h +++ b/internal/platform/timer_impl.h @@ -30,7 +30,6 @@ class TimerImpl : public Timer { absl::AnyInvocable callback) override; void Stop() override; bool IsRunning() override; - bool FireNow() override; private: std::unique_ptr internal_timer_ = nullptr; diff --git a/internal/platform/timer_impl_test.cc b/internal/platform/timer_impl_test.cc index c5625234..5bf4c307 100644 --- a/internal/platform/timer_impl_test.cc +++ b/internal/platform/timer_impl_test.cc @@ -49,16 +49,6 @@ TEST(TimerImpl, TestStartRunningTimer) { timer.Stop(); } -TEST(TimerImpl, TestFireNow) { - TimerImpl timer; - int count = 0; - - EXPECT_TRUE(timer.Start(100, 100, [&count]() { ++count; })); - EXPECT_TRUE(timer.FireNow()); - timer.Stop(); - EXPECT_EQ(count, 1); -} - TEST(TimerImpl, TestStopAfterFire) { TimerImpl timer; absl::Notification notification; diff --git a/internal/test/fake_timer.cc b/internal/test/fake_timer.cc index 773bdb5b..af2bd2be 100644 --- a/internal/test/fake_timer.cc +++ b/internal/test/fake_timer.cc @@ -84,15 +84,6 @@ void FakeTimer::ClockUpdated() { timer_data_ = timer_data; } -bool FakeTimer::FireNow() { - if (IsRunning()) { - timer_data_.callback(); - return true; - } - - return false; -} - bool FakeTimer::InternalStart(int delay, int period, absl::AnyInvocable callback) { if (delay < 0 || period < 0 || callback == nullptr) { diff --git a/internal/test/fake_timer.h b/internal/test/fake_timer.h index 003b33d7..09604eed 100644 --- a/internal/test/fake_timer.h +++ b/internal/test/fake_timer.h @@ -33,7 +33,6 @@ class FakeTimer : public Timer { absl::AnyInvocable callback) override; void Stop() override; bool IsRunning() override; - bool FireNow() override; private: struct TimerData { diff --git a/internal/test/fake_timer_test.cc b/internal/test/fake_timer_test.cc index f90cb042..26e7d4e8 100644 --- a/internal/test/fake_timer_test.cc +++ b/internal/test/fake_timer_test.cc @@ -118,17 +118,6 @@ TEST(FakeTimer, TestTimerDestructor) { EXPECT_EQ(clock.GetObserversCount(), 0); } -TEST(FakeTimer, TestTimerFireNow) { - FakeClock clock; - int count = 0; - FakeTimer timer(&clock); - auto callback = [&count]() { ++count; }; - timer.Start(200, 100, callback); - timer.FireNow(); - timer.Stop(); - EXPECT_EQ(count, 1); -} - TEST(FakeTimer, CloseTimerInTimerProc) { int count = 0; FakeClock clock;