mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-01 11:06:04 +08:00
lockstep_scheduler: use a static lock in usleep_until
less function calls
This commit is contained in:
@@ -87,10 +87,8 @@ int LockstepScheduler::cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *loc
|
|||||||
|
|
||||||
int LockstepScheduler::usleep_until(uint64_t time_us)
|
int LockstepScheduler::usleep_until(uint64_t time_us)
|
||||||
{
|
{
|
||||||
pthread_mutex_t lock;
|
pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
pthread_mutex_init(&lock, nullptr);
|
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
|
||||||
pthread_cond_t cond;
|
|
||||||
pthread_cond_init(&cond, nullptr);
|
|
||||||
|
|
||||||
pthread_mutex_lock(&lock);
|
pthread_mutex_lock(&lock);
|
||||||
|
|
||||||
@@ -103,8 +101,5 @@ int LockstepScheduler::usleep_until(uint64_t time_us)
|
|||||||
|
|
||||||
pthread_mutex_unlock(&lock);
|
pthread_mutex_unlock(&lock);
|
||||||
|
|
||||||
pthread_cond_destroy(&cond);
|
|
||||||
pthread_mutex_destroy(&lock);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user