mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
POSIX: Set the thread name for better debugging
This commit is contained in:
parent
9ee4760fe0
commit
0c2b6bf9d1
@ -75,6 +75,7 @@ static task_entry taskmap[PX4_MAX_TASKS] = {};
|
||||
|
||||
typedef struct {
|
||||
px4_main_t entry;
|
||||
const char* name;
|
||||
int argc;
|
||||
char *argv[];
|
||||
// strings are allocated after the
|
||||
@ -83,6 +84,19 @@ typedef struct {
|
||||
static void *entry_adapter(void *ptr)
|
||||
{
|
||||
pthdata_t *data = (pthdata_t *) ptr;
|
||||
|
||||
int rv;
|
||||
// set the threads name
|
||||
#ifdef __PX4_DARWIN
|
||||
rv = pthread_setname_np(data->name);
|
||||
#else
|
||||
rv = pthread_setname_np(pthread_self(), data->name);
|
||||
#endif
|
||||
|
||||
if (rv) {
|
||||
PX4_ERR("px4_task_spawn_cmd: failed to set name of thread %d %d\n", rv, errno);
|
||||
}
|
||||
|
||||
data->entry(data->argc, data->argv);
|
||||
free(ptr);
|
||||
PX4_DEBUG("Before px4_task_exit");
|
||||
@ -132,6 +146,7 @@ px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int
|
||||
memset(taskdata, 0, structsize + len);
|
||||
offset = ((unsigned long)taskdata) + structsize;
|
||||
|
||||
taskdata->name = name;
|
||||
taskdata->entry = entry;
|
||||
taskdata->argc = argc;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user