diff --git a/internal/platform/implementation/windows/BUILD b/internal/platform/implementation/windows/BUILD index b1705b0e..f102b395 100644 --- a/internal/platform/implementation/windows/BUILD +++ b/internal/platform/implementation/windows/BUILD @@ -49,6 +49,7 @@ cc_library( "//internal/platform:base", "//internal/platform:logging", "//internal/platform/implementation:types", + "//internal/platform/implementation/windows:comm", "//internal/platform/implementation/windows/generated:types", "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/synchronization", diff --git a/internal/platform/implementation/windows/timer.cc b/internal/platform/implementation/windows/timer.cc index b6fbed51..c27846ef 100644 --- a/internal/platform/implementation/windows/timer.cc +++ b/internal/platform/implementation/windows/timer.cc @@ -92,7 +92,18 @@ bool Timer::FireNow() { return false; } - callback_(); + if (task_executor_ == nullptr) { + task_executor_ = std::make_unique(); + } + + if (task_executor_ == nullptr) { + NEARBY_LOGS(ERROR) + << "Failed to fire the task due to cannot create executor."; + return false; + } + + task_executor_->Execute([&]() { callback_(); }); + return true; } diff --git a/internal/platform/implementation/windows/timer.h b/internal/platform/implementation/windows/timer.h index 9c56c253..8b9d9806 100644 --- a/internal/platform/implementation/windows/timer.h +++ b/internal/platform/implementation/windows/timer.h @@ -22,6 +22,7 @@ #include "absl/base/thread_annotations.h" #include "absl/synchronization/mutex.h" #include "internal/platform/implementation/timer.h" +#include "internal/platform/implementation/windows/submittable_executor.h" namespace nearby { namespace windows { @@ -43,9 +44,11 @@ class Timer : public api::Timer { mutable absl::Mutex mutex_; int delay_ ABSL_GUARDED_BY(mutex_); int interval_ ABSL_GUARDED_BY(mutex_); - absl::AnyInvocable callback_ ABSL_GUARDED_BY(mutex_); + absl::AnyInvocable callback_; HANDLE handle_ ABSL_GUARDED_BY(mutex_) = nullptr; HANDLE timer_queue_handle_ ABSL_GUARDED_BY(mutex_) = nullptr; + std::unique_ptr task_executor_ ABSL_GUARDED_BY(mutex_) = + nullptr; }; } // namespace windows