px4_getpid: return the taskmap index instead of pthread_self()

this makes it consistent with other functions, like px4_task_spawn_cmd()
and px4_task_kill()
This commit is contained in:
Beat Küng
2016-09-30 13:50:51 +02:00
committed by Julian Oes
parent a51d1bc5dc
commit 1d111cb254
6 changed files with 21 additions and 13 deletions
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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;
@@ -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;
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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 */
@@ -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;