mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-16 06:53:33 +08:00
Preventing recursive calls of Scheduler::spin()
This commit is contained in:
@@ -70,6 +70,7 @@ class Scheduler : Noncopyable
|
||||
MonotonicTime prev_cleanup_ts_;
|
||||
MonotonicDuration deadline_resolution_;
|
||||
MonotonicDuration cleanup_period_;
|
||||
bool inside_spin_;
|
||||
|
||||
MonotonicTime computeDispatcherSpinDeadline(MonotonicTime spin_deadline) const;
|
||||
void pollCleanup(MonotonicTime mono_ts, uint32_t num_frames_processed_with_last_spin);
|
||||
@@ -80,6 +81,7 @@ public:
|
||||
, prev_cleanup_ts_(sysclock.getMonotonic())
|
||||
, deadline_resolution_(MonotonicDuration::fromMSec(DefaultDeadlineResolutionMs))
|
||||
, cleanup_period_(MonotonicDuration::fromMSec(DefaultCleanupPeriodMs))
|
||||
, inside_spin_(false)
|
||||
{ }
|
||||
|
||||
int spin(MonotonicTime deadline);
|
||||
|
||||
@@ -154,6 +154,13 @@ void Scheduler::pollCleanup(MonotonicTime mono_ts, uint32_t num_frames_processed
|
||||
|
||||
int Scheduler::spin(MonotonicTime deadline)
|
||||
{
|
||||
if (inside_spin_) // Preventing recursive calls
|
||||
{
|
||||
assert(0);
|
||||
return -1;
|
||||
}
|
||||
inside_spin_ = true;
|
||||
|
||||
int retval = 0;
|
||||
while (true)
|
||||
{
|
||||
@@ -171,6 +178,8 @@ int Scheduler::spin(MonotonicTime deadline)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
inside_spin_ = false;
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user