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 void
set_memory_strategy(memory_strategy::MemoryStrategySharedPtr memory_strategy) 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."); throw std::runtime_error("Received NULL memory strategy in executor.");
} }
_memory_strategy = memory_strategy; _memory_strategy = memory_strategy;
} }
protected: protected:
void void
execute_any_executable(AnyExecutableSharedPtr & any_exec) 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 namespace executor
{ {
class Executor; class Executor;
}; }
namespace memory_strategy namespace memory_strategy
{ {
@ -36,7 +36,6 @@ class MemoryStrategy
friend class executor::Executor; friend class executor::Executor;
public: public:
virtual void ** borrow_handles(HandleType type, size_t number_of_handles) virtual void ** borrow_handles(HandleType type, size_t number_of_handles)
{ {
return static_cast<void **>(rcl_malloc(sizeof(void *) * number_of_handles)); return static_cast<void **>(rcl_malloc(sizeof(void *) * number_of_handles));
@ -63,9 +62,7 @@ public:
} }
protected: protected:
private: private:
}; };
typedef std::shared_ptr<MemoryStrategy> MemoryStrategySharedPtr; typedef std::shared_ptr<MemoryStrategy> MemoryStrategySharedPtr;

View file

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