POSIX: px4_getpid() fix

Since the PX4 code uses both px4_task and pthread APIs,
px4_getpid() must be save to call from either context.

On posix, this means we have to always return the pthread ID.

Reverted simulator change of pthread to px4_task

There may have been side effects if this was build for a target that
has process/task scoped file descriptors. It is now safe to call
px4_getpid() from this pthread context with this change for the
posix build for px4_getpid().

Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
Mark Charlebois
2015-06-15 08:25:57 -07:00
parent 75ef0e1709
commit d66b6ea701
6 changed files with 25 additions and 28 deletions
@@ -278,21 +278,9 @@ void px4_show_tasks()
__BEGIN_DECLS
int px4_getpid()
unsigned long 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].isused && taskmap[i].pid == pid) {
return i;
}
}
PX4_ERR("px4_getpid() called from unknown thread context!");
return -EINVAL;
return (unsigned long)pthread_self();
}
const char *getprogname();
+1 -1
View File
@@ -99,7 +99,7 @@ __EXPORT int px4_ioctl(int fd, int cmd, unsigned long arg);
__EXPORT int px4_poll(px4_pollfd_struct_t *fds, nfds_t nfds, int timeout);
__EXPORT int px4_fsync(int fd);
__EXPORT int px4_access(const char *pathname, int mode);
__EXPORT int px4_getpid(void);
__EXPORT unsigned long px4_getpid(void);
__END_DECLS
#else