mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-05 00:21:35 +08:00
ModuleBase: add wait_until_running() method
This commit is contained in:
@@ -52,16 +52,10 @@ int SendEvent::task_spawn(int argc, char *argv[])
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = 0;
|
ret = wait_until_running();
|
||||||
|
|
||||||
do {
|
if (ret < 0) {
|
||||||
/* wait up to 1s */
|
return ret;
|
||||||
usleep(2500);
|
|
||||||
|
|
||||||
} while (!_object && ++i < 400);
|
|
||||||
|
|
||||||
if (i == 400) {
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_task_id = task_id_is_work_queue;
|
_task_id = task_id_is_work_queue;
|
||||||
|
|||||||
@@ -320,6 +320,28 @@ protected:
|
|||||||
unlock_module();
|
unlock_module();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wait until _object got initialized (from the new thread). This can be called from task_spawn().
|
||||||
|
* @return 0 on success, -1 on timeout.
|
||||||
|
*/
|
||||||
|
static int wait_until_running()
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
/* wait up to 1s */
|
||||||
|
usleep(2500);
|
||||||
|
|
||||||
|
} while (!_object && ++i < 400);
|
||||||
|
|
||||||
|
if (i == 400) {
|
||||||
|
PX4_ERR("Timed out while waiting for thread to start");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/** get the module's object instance (this is null if it's not running) */
|
/** get the module's object instance (this is null if it's not running) */
|
||||||
static T *get_instance()
|
static T *get_instance()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user