forked from Archive/PX4-Autopilot
POSIX: Fixed px4_getpid() calls from shell context
When px4_getpid() was called from the shell, there was no opaque thread ID to return. Added a special thread ID for the shell context. This ID only works for px4_getpid() and cannot be used for other px4_task_*() calls. Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
parent
30969eb10c
commit
18304a2a0d
|
@ -48,6 +48,8 @@
|
|||
#include "systemlib/param/param.h"
|
||||
#include "hrt_work.h"
|
||||
|
||||
extern pthread_t _shell_task_id;
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
long PX4_TICKS_PER_SEC = sysconf(_SC_CLK_TCK);
|
||||
|
@ -63,6 +65,8 @@ void init_once(void);
|
|||
|
||||
void init_once(void)
|
||||
{
|
||||
_shell_task_id = pthread_self();
|
||||
PX4_INFO("Shell id is %lu", _shell_task_id);
|
||||
work_queues_init();
|
||||
hrt_work_queue_init();
|
||||
hrt_init();
|
||||
|
|
|
@ -58,6 +58,10 @@
|
|||
#define MAX_CMD_LEN 100
|
||||
|
||||
#define PX4_MAX_TASKS 100
|
||||
#define SHELL_TASK_ID (PX4_MAX_TASKS+1)
|
||||
|
||||
pthread_t _shell_task_id = 0;
|
||||
|
||||
struct task_entry
|
||||
{
|
||||
pthread_t pid;
|
||||
|
@ -243,7 +247,7 @@ int px4_task_kill(px4_task_t id, int sig)
|
|||
pthread_t pid;
|
||||
PX4_DEBUG("Called px4_task_kill %d", sig);
|
||||
|
||||
if (id < PX4_MAX_TASKS && taskmap[id].pid != 0)
|
||||
if (id < PX4_MAX_TASKS && taskmap[id].isused && taskmap[id].pid != 0)
|
||||
pid = taskmap[id].pid;
|
||||
else
|
||||
return -EINVAL;
|
||||
|
@ -278,13 +282,16 @@ int px4_getpid()
|
|||
{
|
||||
pthread_t pid = pthread_self();
|
||||
|
||||
if (pid == _shell_task_id)
|
||||
return SHELL_TASK_ID;
|
||||
|
||||
// Get pthread ID from the opaque ID
|
||||
for (int i=0; i<PX4_MAX_TASKS; ++i) {
|
||||
if (taskmap[i].pid == pid) {
|
||||
if (taskmap[i].isused && taskmap[i].pid == pid) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
PX4_ERR("px4_getpid() called from non-thread context!");
|
||||
PX4_ERR("px4_getpid() called from unknown thread context!");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue