mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-03 14:10:34 +08:00
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:
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user