diff --git a/src/modules/mavlink/mavlink_receiver.cpp b/src/modules/mavlink/mavlink_receiver.cpp index 2bbf7463a5..8537bd14c4 100644 --- a/src/modules/mavlink/mavlink_receiver.cpp +++ b/src/modules/mavlink/mavlink_receiver.cpp @@ -2079,7 +2079,7 @@ MavlinkReceiver::receive_thread(void *arg) { char thread_name[24]; sprintf(thread_name, "mavlink_rcv_if%d", _mavlink->get_instance_id()); - px4_prctl(PR_SET_NAME, thread_name, getpid()); + px4_prctl(PR_SET_NAME, thread_name, px4_getpid()); } const int timeout = 500; diff --git a/src/modules/uORB/uORBDevices.hpp b/src/modules/uORB/uORBDevices.hpp index 658526af03..69d6df099c 100644 --- a/src/modules/uORB/uORBDevices.hpp +++ b/src/modules/uORB/uORBDevices.hpp @@ -232,7 +232,7 @@ private: We allow one publisher to have an open file descriptor at the same time. */ bool _IsRemoteSubscriberPresent; #else - unsigned long _publisher; /**< if nonzero, current publisher. Only used inside the advertise call. + px4_task_t _publisher; /**< if nonzero, current publisher. Only used inside the advertise call. We allow one publisher to have an open file descriptor at the same time. */ #endif int32_t _subscriber_count; diff --git a/src/platforms/posix/px4_layer/px4_posix_tasks.cpp b/src/platforms/posix/px4_layer/px4_posix_tasks.cpp index 3f5c227bd1..754ce010fc 100644 --- a/src/platforms/posix/px4_layer/px4_posix_tasks.cpp +++ b/src/platforms/posix/px4_layer/px4_posix_tasks.cpp @@ -387,9 +387,21 @@ bool px4_task_is_running(const char *taskname) return false; } -unsigned long px4_getpid() +px4_task_t px4_getpid() { - return (unsigned long)pthread_self(); + pthread_t pid = pthread_self(); + px4_task_t ret = -1; + + pthread_mutex_lock(&task_mutex); + + for (int i = 0; i < PX4_MAX_TASKS; i++) { + if (taskmap[i].isused && taskmap[i].pid == pid) { + ret = i; + } + } + + pthread_mutex_unlock(&task_mutex); + return ret; } const char *px4_get_taskname() @@ -410,7 +422,7 @@ const char *px4_get_taskname() return prog_name; } -int px4_prctl(int option, const char *arg2, unsigned pid) +int px4_prctl(int option, const char *arg2, px4_task_t pid) { int rv; diff --git a/src/platforms/px4_posix.h b/src/platforms/px4_posix.h index ed556e63b5..f31616710a 100644 --- a/src/platforms/px4_posix.h +++ b/src/platforms/px4_posix.h @@ -109,7 +109,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 unsigned long px4_getpid(void); +__EXPORT px4_task_t px4_getpid(void); __EXPORT void px4_enable_sim_lockstep(void); __EXPORT void px4_sim_start_delay(void); diff --git a/src/platforms/px4_tasks.h b/src/platforms/px4_tasks.h index 6fa3619ae5..0960745c5d 100644 --- a/src/platforms/px4_tasks.h +++ b/src/platforms/px4_tasks.h @@ -131,7 +131,7 @@ __EXPORT bool px4_task_is_running(const char *taskname); #ifdef __PX4_POSIX /** set process (and thread) options */ -__EXPORT int px4_prctl(int option, const char *arg2, unsigned pid); +__EXPORT int px4_prctl(int option, const char *arg2, px4_task_t pid); #endif /** return the name of the current task */ diff --git a/src/platforms/qurt/px4_layer/px4_qurt_tasks.cpp b/src/platforms/qurt/px4_layer/px4_qurt_tasks.cpp index 00739dfafb..5d1093159d 100644 --- a/src/platforms/qurt/px4_layer/px4_qurt_tasks.cpp +++ b/src/platforms/qurt/px4_layer/px4_qurt_tasks.cpp @@ -326,7 +326,7 @@ void px4_show_tasks() } -unsigned long px4_getpid() +px4_task_t px4_getpid() { pthread_t pid = pthread_self(); // @@ -340,10 +340,6 @@ unsigned long px4_getpid() } } -#ifndef __PX4_QURT - // XXX This doesn't seem to be working on QURT - PX4_ERR("px4_getpid() called from unknown thread context!"); -#endif return ~0; } @@ -386,7 +382,7 @@ int px4_sem_timedwait(px4_sem_t *sem, const struct timespec *ts) return 0; } -int px4_prctl(int option, const char *arg2, unsigned pid) +int px4_prctl(int option, const char *arg2, px4_task_t pid) { int rv;