Uncrustified

This commit is contained in:
Jackie Kay 2015-07-13 14:49:08 -07:00
parent 41cc5324f4
commit 0557b115bc
4 changed files with 44 additions and 61 deletions

View file

@ -120,15 +120,13 @@ public:
void
set_memory_strategy(memory_strategy::MemoryStrategySharedPtr memory_strategy)
{
if (memory_strategy == nullptr)
{
if (memory_strategy == nullptr) {
throw std::runtime_error("Received NULL memory strategy in executor.");
}
_memory_strategy = memory_strategy;
}
protected:
void
execute_any_executable(AnyExecutableSharedPtr & any_exec)
{

View file

@ -25,7 +25,7 @@ enum class HandleType{subscriber_handle, service_handle, client_handle, guard_co
namespace executor
{
class Executor;
};
}
namespace memory_strategy
{
@ -36,7 +36,6 @@ class MemoryStrategy
friend class executor::Executor;
public:
virtual void ** borrow_handles(HandleType type, size_t number_of_handles)
{
return static_cast<void **>(rcl_malloc(sizeof(void *) * number_of_handles));
@ -63,9 +62,7 @@ public:
}
protected:
private:
};
typedef std::shared_ptr<MemoryStrategy> MemoryStrategySharedPtr;

View file

@ -1,4 +1,3 @@
// Copyright 2015 Open Source Robotics Foundation, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
@ -31,7 +30,6 @@ class StaticMemoryStrategy : public memory_strategy::MemoryStrategy
{
public:
StaticMemoryStrategy()
{
memset(_memory_pool, 0, _pool_size);
@ -42,21 +40,18 @@ public:
_pool_seq = 0;
_exec_seq = 0;
for (size_t i = 0; i < _pool_size; ++i)
{
for (size_t i = 0; i < _pool_size; ++i) {
_memory_map[_memory_pool[i]] = 0;
}
for (size_t i = 0; i < _max_executables; ++i)
{
for (size_t i = 0; i < _max_executables; ++i) {
_executable_pool[i] = std::make_shared<executor::AnyExecutable>(executor::AnyExecutable());
}
}
void ** borrow_handles(HandleType type, size_t number_of_handles)
{
switch(type)
{
switch (type) {
case HandleType::subscriber_handle:
return _subscriber_pool;
case HandleType::service_handle:
@ -73,8 +68,7 @@ public:
void return_handles(HandleType type, void ** handles)
{
switch(type)
{
switch (type) {
case HandleType::subscriber_handle:
memset(_subscriber_pool, 0, _max_subscribers);
break;
@ -95,8 +89,7 @@ public:
executor::AnyExecutableSharedPtr instantiate_next_executable()
{
if (_exec_seq >= _max_executables)
{
if (_exec_seq >= _max_executables) {
// wrap around
_exec_seq = 0;
}
@ -110,14 +103,12 @@ public:
{
// Extremely naive static allocation strategy
// Keep track of block size at a given pointer
if (_pool_seq + size > _pool_size)
{
if (_pool_seq + size > _pool_size) {
// Start at 0
_pool_seq = 0;
}
void * ptr = _memory_pool[_pool_seq];
if (_memory_map.count(ptr) == 0)
{
if (_memory_map.count(ptr) == 0) {
// We expect to have the state for all blocks pre-mapped into _memory_map
throw std::runtime_error("Unexpected pointer in rcl_malloc.");
}
@ -129,8 +120,7 @@ public:
void rcl_free(void * ptr)
{
if (_memory_map.count(ptr) == 0)
{
if (_memory_map.count(ptr) == 0) {
// We expect to have the state for all blocks pre-mapped into _memory_map
throw std::runtime_error("Unexpected pointer in rcl_free.");
}
@ -139,8 +129,6 @@ public:
}
protected:
private:
static const size_t _pool_size = 1024;
static const size_t _max_subscribers = 10;