Skip to content
Snippets Groups Projects
Commit 3b64be44 authored by Beat Küng's avatar Beat Küng
Browse files

ModuleBase: add wait_until_running() method

parent 6778be2c
No related branches found
No related tags found
No related merge requests found
......@@ -52,16 +52,10 @@ int SendEvent::task_spawn(int argc, char *argv[])
return ret;
}
int i = 0;
ret = wait_until_running();
do {
/* wait up to 1s */
usleep(2500);
} while (!_object && ++i < 400);
if (i == 400) {
return -1;
if (ret < 0) {
return ret;
}
_task_id = task_id_is_work_queue;
......
......@@ -320,6 +320,28 @@ protected:
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) */
static T *get_instance()
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment