From 5bae5b0c530a861c218dffbaaee7765fb8f1498b Mon Sep 17 00:00:00 2001 From: etkmao Date: Mon, 28 Oct 2024 16:50:51 +0800 Subject: [PATCH] fix(core): fix looper_driver for android and ios --- modules/footstone/include/footstone/cv_driver.h | 3 --- modules/footstone/include/footstone/driver.h | 5 +++-- .../include/footstone/platform/adr/looper_driver.h | 2 +- .../include/footstone/platform/ios/looper_driver.h | 4 ++-- modules/footstone/src/cv_driver.cc | 14 -------------- .../footstone/src/platform/adr/looper_driver.cc | 2 +- .../footstone/src/platform/ios/looper_driver.cc | 2 +- 7 files changed, 8 insertions(+), 24 deletions(-) diff --git a/modules/footstone/include/footstone/cv_driver.h b/modules/footstone/include/footstone/cv_driver.h index 9b53231d5ff..de6a1698290 100644 --- a/modules/footstone/include/footstone/cv_driver.h +++ b/modules/footstone/include/footstone/cv_driver.h @@ -35,15 +35,12 @@ class CVDriver: public Driver { virtual ~CVDriver() = default; virtual void Notify() override; - virtual void WaitFor(const TimeDelta& delta) override; - virtual std::mutex& Mutex() override; virtual void WaitFor(const TimeDelta& delta, std::unique_lock& lock) override; virtual void Start() override; virtual void Terminate() override; private: std::condition_variable cv_; - std::mutex mutex_; }; } diff --git a/modules/footstone/include/footstone/driver.h b/modules/footstone/include/footstone/driver.h index eab90e14bf7..c18869e6741 100644 --- a/modules/footstone/include/footstone/driver.h +++ b/modules/footstone/include/footstone/driver.h @@ -35,8 +35,7 @@ class Driver { virtual ~Driver() = default; virtual void Notify() = 0; - virtual void WaitFor(const TimeDelta& delta) = 0; - virtual std::mutex& Mutex() = 0; + std::mutex& Mutex() { return mutex_; } virtual void WaitFor(const TimeDelta& delta, std::unique_lock& lock) = 0; virtual void Start() = 0; virtual void Terminate() = 0; @@ -62,6 +61,8 @@ class Driver { * */ bool is_exit_immediately_; + + std::mutex mutex_; }; } diff --git a/modules/footstone/include/footstone/platform/adr/looper_driver.h b/modules/footstone/include/footstone/platform/adr/looper_driver.h index 213dd9c3042..e6f4e5053dc 100644 --- a/modules/footstone/include/footstone/platform/adr/looper_driver.h +++ b/modules/footstone/include/footstone/platform/adr/looper_driver.h @@ -36,7 +36,7 @@ class LooperDriver: public Driver { virtual ~LooperDriver(); virtual void Notify() override; - virtual void WaitFor(const TimeDelta& delta) override; + virtual void WaitFor(const TimeDelta& delta, std::unique_lock& lock) override; virtual void Start() override; virtual void Terminate() override; diff --git a/modules/footstone/include/footstone/platform/ios/looper_driver.h b/modules/footstone/include/footstone/platform/ios/looper_driver.h index 1ec849a044f..1e07e2c90e8 100644 --- a/modules/footstone/include/footstone/platform/ios/looper_driver.h +++ b/modules/footstone/include/footstone/platform/ios/looper_driver.h @@ -35,10 +35,10 @@ class LooperDriver: public Driver { virtual ~LooperDriver(); virtual void Notify() override; - virtual void WaitFor(const TimeDelta& delta) override; + virtual void WaitFor(const TimeDelta& delta, std::unique_lock& lock) override; virtual void Start() override; virtual void Terminate() override; - + void OnTimerFire(CFRunLoopTimerRef timer); private: diff --git a/modules/footstone/src/cv_driver.cc b/modules/footstone/src/cv_driver.cc index 724720d73b9..ff180f7100e 100644 --- a/modules/footstone/src/cv_driver.cc +++ b/modules/footstone/src/cv_driver.cc @@ -28,20 +28,6 @@ void CVDriver::Notify() { cv_.notify_one(); } -void CVDriver::WaitFor(const TimeDelta& delta) { - std::unique_lock lock(mutex_); - - if (delta != TimeDelta::Max() && delta >= TimeDelta::Zero()) { - cv_.wait_for(lock, std::chrono::nanoseconds(delta.ToNanoseconds())); - } else { - cv_.wait(lock); - } -} - -std::mutex& CVDriver::Mutex() { - return mutex_; -} - void CVDriver::WaitFor(const TimeDelta& delta, std::unique_lock& lock) { if (delta != TimeDelta::Max() && delta >= TimeDelta::Zero()) { cv_.wait_for(lock, std::chrono::nanoseconds(delta.ToNanoseconds())); diff --git a/modules/footstone/src/platform/adr/looper_driver.cc b/modules/footstone/src/platform/adr/looper_driver.cc index 22ea02c9daa..96a3b371122 100644 --- a/modules/footstone/src/platform/adr/looper_driver.cc +++ b/modules/footstone/src/platform/adr/looper_driver.cc @@ -57,7 +57,7 @@ void LooperDriver::Notify() { timerfd_settime(fd_, TFD_TIMER_ABSTIME, &spec, nullptr); } -void LooperDriver::WaitFor(const TimeDelta& delta) { +void LooperDriver::WaitFor(const TimeDelta& delta, std::unique_lock& lock) { auto nano_secs = delta.ToNanoseconds(); if (nano_secs < 1) { nano_secs = 1; diff --git a/modules/footstone/src/platform/ios/looper_driver.cc b/modules/footstone/src/platform/ios/looper_driver.cc index b817da01eac..eac5e0d0bcb 100644 --- a/modules/footstone/src/platform/ios/looper_driver.cc +++ b/modules/footstone/src/platform/ios/looper_driver.cc @@ -56,7 +56,7 @@ void LooperDriver::Notify() { CFAbsoluteTimeGetCurrent()); } -void LooperDriver::WaitFor(const TimeDelta& delta) { +void LooperDriver::WaitFor(const TimeDelta& delta, std::unique_lock& lock) { CFRunLoopTimerSetNextFireDate( delayed_wake_timer_, CFAbsoluteTimeGetCurrent() + delta.ToSecondsF());