Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions rttest/src/rttest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <algorithm>
#include <cassert>
#include <charconv>
#include <cmath>
#include <format> // NOLINT(build/include_order)
#include <fstream>
Expand Down Expand Up @@ -250,7 +251,8 @@ int Rttest::read_args(int argc, char ** argv)
switch (c) {
case 'i':
{
int arg = atoi(optarg);
int arg = 0;
std::from_chars(optarg, optarg + strlen(optarg), arg);
if (arg < 0) {
iterations = 0;
} else {
Expand Down Expand Up @@ -280,8 +282,12 @@ int Rttest::read_args(int argc, char ** argv)
}
break;
case 't':
sched_priority = atoi(optarg);
break;
{
int prio = 0;
std::from_chars(optarg, optarg + strlen(optarg), prio);
sched_priority = prio;
break;
}
case 's':
{
std::string input(optarg);
Expand Down Expand Up @@ -328,7 +334,7 @@ int Rttest::read_args(int argc, char ** argv)

int rttest_get_params(struct rttest_params * params_in)
{
if (params_in == NULL) {
if (params_in == nullptr) {
return -1;
}

Expand Down Expand Up @@ -557,7 +563,7 @@ int Rttest::spin_once(
struct timespec wakeup_time, current_time;
multiply_timespec(update_period, i, &wakeup_time);
add_timespecs(start_time, &wakeup_time, &wakeup_time);
clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &wakeup_time, NULL);
clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &wakeup_time, nullptr);
clock_gettime(CLOCK_MONOTONIC, &current_time);

this->record_jitter(&wakeup_time, &current_time, i);
Expand Down Expand Up @@ -751,7 +757,7 @@ int Rttest::accumulate_statistics(size_t iteration)

int Rttest::calculate_statistics(struct rttest_results * output)
{
if (output == NULL) {
if (output == nullptr) {
fprintf(stderr, "Need to allocate rttest_results struct\n");
return -1;
}
Expand Down Expand Up @@ -789,7 +795,7 @@ int rttest_calculate_statistics(struct rttest_results * results)

int rttest_get_statistics(struct rttest_results * output)
{
if (output == NULL) {
if (output == nullptr) {
return -1;
}

Expand Down Expand Up @@ -826,7 +832,7 @@ int rttest_get_sample_at(const size_t iteration, int64_t * sample)
if (!thread_rttest_instance) {
return -1;
}
if (sample == NULL) {
if (sample == nullptr) {
return -1;
}
return thread_rttest_instance->get_sample_at(iteration, *sample);
Expand Down Expand Up @@ -908,7 +914,7 @@ int Rttest::write_results_file(char * filename)
fprintf(stderr, "No sample buffer was saved, not writing results\n");
return -1;
}
if (filename == NULL) {
if (filename == nullptr) {
fprintf(stderr, "No results filename given, not writing results\n");
return -1;
}
Expand Down
34 changes: 18 additions & 16 deletions tlsf_cpp/include/tlsf_cpp/tlsf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,29 @@ struct tlsf_heap_allocator

rcl_allocator_t get_rcl_allocator()
{
rcl_allocator_t allocator = rcl_get_default_allocator();
allocator.allocate = [](size_t size, void * state) -> void * {
return malloc_ex(size, state);
};
allocator.deallocate = [](void * ptr, void * state) {
free_ex(ptr, state);
};
allocator.reallocate = [](void * ptr, size_t size, void * state) -> void * {
return realloc_ex(ptr, size, state);
};
allocator.zero_allocate = [](size_t n, size_t size, void * state) -> void * {
return calloc_ex(n, size, state);
};
allocator.state = memory_pool;
return allocator;
// Designated initializers must follow rcl_allocator_t's declaration order:
// allocate, deallocate, reallocate, zero_allocate, state.
return rcl_allocator_t{
.allocate = [](size_t size, void * state) -> void * {
return malloc_ex(size, state);
},
.deallocate = [](void * ptr, void * state) {
free_ex(ptr, state);
},
.reallocate = [](void * ptr, size_t size, void * state) -> void * {
return realloc_ex(ptr, size, state);
},
.zero_allocate = [](size_t n, size_t size, void * state) -> void * {
return calloc_ex(n, size, state);
},
.state = memory_pool,
};
}

template<typename U>
struct rebind
{
typedef tlsf_heap_allocator<U> other;
using other = tlsf_heap_allocator<U>;
};

char * memory_pool;
Expand Down