Skip to content

Commit

Permalink
fix(core): fix looper_driver for android and ios
Browse files Browse the repository at this point in the history
  • Loading branch information
etkmao committed Oct 28, 2024
1 parent e71f15f commit 5bae5b0
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 24 deletions.
3 changes: 0 additions & 3 deletions modules/footstone/include/footstone/cv_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex>& lock) override;
virtual void Start() override;
virtual void Terminate() override;

private:
std::condition_variable cv_;
std::mutex mutex_;
};

}
Expand Down
5 changes: 3 additions & 2 deletions modules/footstone/include/footstone/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex>& lock) = 0;
virtual void Start() = 0;
virtual void Terminate() = 0;
Expand All @@ -62,6 +61,8 @@ class Driver {
*
*/
bool is_exit_immediately_;

std::mutex mutex_;
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex>& lock) override;
virtual void Start() override;
virtual void Terminate() override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex>& lock) override;
virtual void Start() override;
virtual void Terminate() override;

void OnTimerFire(CFRunLoopTimerRef timer);

private:
Expand Down
14 changes: 0 additions & 14 deletions modules/footstone/src/cv_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,6 @@ void CVDriver::Notify() {
cv_.notify_one();
}

void CVDriver::WaitFor(const TimeDelta& delta) {
std::unique_lock<std::mutex> 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<std::mutex>& lock) {
if (delta != TimeDelta::Max() && delta >= TimeDelta::Zero()) {
cv_.wait_for(lock, std::chrono::nanoseconds(delta.ToNanoseconds()));
Expand Down
2 changes: 1 addition & 1 deletion modules/footstone/src/platform/adr/looper_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex>& lock) {
auto nano_secs = delta.ToNanoseconds();
if (nano_secs < 1) {
nano_secs = 1;
Expand Down
2 changes: 1 addition & 1 deletion modules/footstone/src/platform/ios/looper_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void LooperDriver::Notify() {
CFAbsoluteTimeGetCurrent());
}

void LooperDriver::WaitFor(const TimeDelta& delta) {
void LooperDriver::WaitFor(const TimeDelta& delta, std::unique_lock<std::mutex>& lock) {
CFRunLoopTimerSetNextFireDate(
delayed_wake_timer_,
CFAbsoluteTimeGetCurrent() + delta.ToSecondsF());
Expand Down

0 comments on commit 5bae5b0

Please sign in to comment.