mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-09 01:18:29 -04:00
AP_HAL_Linux: fix perf
Fix warning (warning: declaration of 'perf_count' shadows a member of 'this') and check that perf is not NULL before indirection
This commit is contained in:
parent
259f5f07e8
commit
2f610a400a
@ -105,6 +105,11 @@ static inline uint64_t timespec_to_nsec(const struct timespec *ts)
|
||||
void Util::perf_begin(perf_counter_t perf)
|
||||
{
|
||||
struct perf_counter_elapsed_t *perf_elapsed = (struct perf_counter_elapsed_t *)perf;
|
||||
|
||||
if (perf_elapsed == NULL) {
|
||||
hal.console->printf("Trying to begin uninitialized perf counter\n");
|
||||
return;
|
||||
}
|
||||
if (perf_elapsed->base.type != PC_ELAPSED) {
|
||||
hal.console->printf("perf_begin() called over a perf_counter_t(%s) that"
|
||||
" is not of the PC_ELAPSED type.\n",
|
||||
@ -121,6 +126,11 @@ void Util::perf_end(perf_counter_t perf)
|
||||
{
|
||||
struct perf_counter_elapsed_t *perf_elapsed = (struct perf_counter_elapsed_t *)perf;
|
||||
|
||||
if (perf_elapsed == NULL) {
|
||||
hal.console->printf("Trying to end uninitialized perf counter\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (perf_elapsed->base.type != PC_ELAPSED) {
|
||||
hal.console->printf("perf_end() called over a perf_counter_t(%s) "
|
||||
"that is not of the PC_ELAPSED type.\n",
|
||||
@ -162,16 +172,21 @@ void Util::perf_end(perf_counter_t perf)
|
||||
|
||||
void Util::perf_count(perf_counter_t perf)
|
||||
{
|
||||
struct perf_counter_count_t *perf_count = (struct perf_counter_count_t *)perf;
|
||||
struct perf_counter_count_t *perf_counter = (struct perf_counter_count_t *)perf;
|
||||
|
||||
if (perf_count->base.type != PC_COUNT) {
|
||||
hal.console->printf("perf_count() called over a perf_counter_t(%s) "
|
||||
"that is not of the PC_COUNT type.\n",
|
||||
perf_count->base.name);
|
||||
if (perf_counter == NULL) {
|
||||
hal.console->printf("Trying to count uninitialized perf counter\n");
|
||||
return;
|
||||
}
|
||||
|
||||
perf_count->count++;
|
||||
if (perf_counter->base.type != PC_COUNT) {
|
||||
hal.console->printf("perf_count() called over a perf_counter_t(%s) "
|
||||
"that is not of the PC_COUNT type.\n",
|
||||
perf_counter->base.name);
|
||||
return;
|
||||
}
|
||||
|
||||
perf_counter->count++;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user