mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-21 01:12:11 +00:00
posix: small cleanup
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
* Copyright (C) 2015 Mark Charlebois. All rights reserved.
|
* Copyright (C) 2015-2020 Mark Charlebois. All rights reserved.
|
||||||
* Author: @author Mark Charlebois <charlebm#gmail.com>
|
* Author: @author Mark Charlebois <charlebm@gmail.com>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -33,7 +33,6 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file px4_posix_tasks.c
|
|
||||||
* Implementation of existing task API for Linux
|
* Implementation of existing task API for Linux
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -60,22 +59,18 @@
|
|||||||
#include <px4_platform_common/posix.h>
|
#include <px4_platform_common/posix.h>
|
||||||
#include <systemlib/err.h>
|
#include <systemlib/err.h>
|
||||||
|
|
||||||
#define MAX_CMD_LEN 100
|
|
||||||
|
|
||||||
#define PX4_MAX_TASKS 50
|
#define PX4_MAX_TASKS 50
|
||||||
#define SHELL_TASK_ID (PX4_MAX_TASKS+1)
|
|
||||||
|
|
||||||
pthread_t _shell_task_id = 0;
|
pthread_t _shell_task_id = 0;
|
||||||
pthread_mutex_t task_mutex = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t task_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
struct task_entry {
|
struct task_entry {
|
||||||
pthread_t pid;
|
pthread_t pid{0};
|
||||||
std::string name;
|
std::string name{};
|
||||||
bool isused;
|
bool isused {false};
|
||||||
task_entry() : isused(false) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static task_entry taskmap[PX4_MAX_TASKS] = {};
|
static task_entry taskmap[PX4_MAX_TASKS] {};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
px4_main_t entry;
|
px4_main_t entry;
|
||||||
@@ -89,13 +84,11 @@ static void *entry_adapter(void *ptr)
|
|||||||
{
|
{
|
||||||
pthdata_t *data = (pthdata_t *) ptr;
|
pthdata_t *data = (pthdata_t *) ptr;
|
||||||
|
|
||||||
int rv;
|
|
||||||
|
|
||||||
// set the threads name
|
// set the threads name
|
||||||
#ifdef __PX4_DARWIN
|
#ifdef __PX4_DARWIN
|
||||||
rv = pthread_setname_np(data->name);
|
int rv = pthread_setname_np(data->name);
|
||||||
#else
|
#else
|
||||||
rv = pthread_setname_np(pthread_self(), data->name);
|
int rv = pthread_setname_np(pthread_self(), data->name);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (rv) {
|
if (rv) {
|
||||||
@@ -114,8 +107,6 @@ static void *entry_adapter(void *ptr)
|
|||||||
px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int stack_size, px4_main_t entry,
|
px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int stack_size, px4_main_t entry,
|
||||||
char *const argv[])
|
char *const argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
int i;
|
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
unsigned int len = 0;
|
unsigned int len = 0;
|
||||||
struct sched_param param = {};
|
struct sched_param param = {};
|
||||||
@@ -150,7 +141,7 @@ px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int
|
|||||||
taskdata->entry = entry;
|
taskdata->entry = entry;
|
||||||
taskdata->argc = argc;
|
taskdata->argc = argc;
|
||||||
|
|
||||||
for (i = 0; i < argc; i++) {
|
for (int i = 0; i < argc; ++i) {
|
||||||
PX4_DEBUG("arg %d %s\n", i, argv[i]);
|
PX4_DEBUG("arg %d %s\n", i, argv[i]);
|
||||||
taskdata->argv[i] = (char *)offset;
|
taskdata->argv[i] = (char *)offset;
|
||||||
strcpy((char *)offset, argv[i]);
|
strcpy((char *)offset, argv[i]);
|
||||||
@@ -226,6 +217,8 @@ px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int
|
|||||||
|
|
||||||
px4_task_t taskid = 0;
|
px4_task_t taskid = 0;
|
||||||
|
|
||||||
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < PX4_MAX_TASKS; ++i) {
|
for (i = 0; i < PX4_MAX_TASKS; ++i) {
|
||||||
if (!taskmap[i].isused) {
|
if (!taskmap[i].isused) {
|
||||||
taskmap[i].name = name;
|
taskmap[i].name = name;
|
||||||
@@ -307,10 +300,11 @@ int px4_task_delete(px4_task_t id)
|
|||||||
|
|
||||||
void px4_task_exit(int ret)
|
void px4_task_exit(int ret)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
pthread_t pid = pthread_self();
|
pthread_t pid = pthread_self();
|
||||||
|
|
||||||
// Get pthread ID from the opaque ID
|
// Get pthread ID from the opaque ID
|
||||||
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < PX4_MAX_TASKS; ++i) {
|
for (i = 0; i < PX4_MAX_TASKS; ++i) {
|
||||||
if (taskmap[i].pid == pid) {
|
if (taskmap[i].pid == pid) {
|
||||||
pthread_mutex_lock(&task_mutex);
|
pthread_mutex_lock(&task_mutex);
|
||||||
@@ -422,7 +416,7 @@ const char *px4_get_taskname()
|
|||||||
|
|
||||||
int px4_prctl(int option, const char *arg2, px4_task_t pid)
|
int px4_prctl(int option, const char *arg2, px4_task_t pid)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv = -1;
|
||||||
|
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case PR_SET_NAME:
|
case PR_SET_NAME:
|
||||||
@@ -435,7 +429,6 @@ int px4_prctl(int option, const char *arg2, px4_task_t pid)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
rv = -1;
|
|
||||||
PX4_WARN("FAILED SETTING TASK NAME");
|
PX4_WARN("FAILED SETTING TASK NAME");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user