ModuleBase: add wait_until_running() method

This commit is contained in:
Beat Küng
2017-05-03 11:41:21 +02:00
parent 6778be2c6e
commit 3b64be44f4
2 changed files with 25 additions and 9 deletions
+3 -9
View File
@@ -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;
+22
View File
@@ -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()
{