Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Buffer.hxx File Reference
#include <memory>
#include <atomic>
#include <new>
#include <cstdint>
#include <cstdlib>
#include <cstdarg>
#include "executor/Executable.hxx"
#include "executor/Notifiable.hxx"
#include "os/OS.hxx"
#include "utils/Atomic.hxx"
#include "utils/MultiMap.hxx"
#include "utils/QMember.hxx"
#include "utils/Queue.hxx"
#include "utils/macros.h"

Go to the source code of this file.

Classes

class  BufferBase
 Abstract base class for all Buffers. More...
 
class  Buffer< T >
 Base class for all QMember types that hold data in an expandable format. More...
 
struct  BufferDelete< T >
 Helper class for correctly deleting a buffer. More...
 
class  Pool
 Pool of previously allocated, but currently unused, items. More...
 
class  Bucket
 This is a struct for storing info about a specific size item in the DynamicPool. More...
 
class  DynamicPool
 A specialization of a pool which can allocate new elements dynamically upon request. More...
 
class  FixedPool
 Pool of fixed number of items which can be allocated up on request. More...
 

Namespaces

namespace  openlcb
 

Typedefs

template<typename T >
using AutoReleaseBuffer = std::unique_ptr< Buffer< T >, BufferDelete< T > >
 This class will automatically unref a Buffer when going out of scope.
 
template<typename T >
using BufferPtr = AutoReleaseBuffer< T >
 Smart pointer for buffers.
 

Functions

Poolinit_main_buffer_pool ()
 Initializes the main buffer pool.
 
template<typename T >
BufferPtr< T > get_buffer_deleter (Buffer< T > *b)
 Helper function to create a BufferPtr of an appropriate type without having to explicitly specify the template argument.
 

Variables

const unsigned LARGEST_BUFFERPOOL_BUCKET
 Ensures that the largest bucket in the main buffer pool is exactly the size of a GenMessage.
 
DynamicPoolmainBufferPool
 main buffer pool instance
 
void * g_current_alloc
 This pointer will be saved for debugging the current allocation source.
 

Detailed Description

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

This file provides buffers with allocation and freelist/reuse mechanisms.

Author
Stuart W. Baker
Date
3 August 2013

Definition in file Buffer.hxx.

Typedef Documentation

◆ AutoReleaseBuffer

template<typename T >
using AutoReleaseBuffer = std::unique_ptr<Buffer<T>, BufferDelete<T> >

This class will automatically unref a Buffer when going out of scope.

Definition at line 256 of file Buffer.hxx.

◆ BufferPtr

template<typename T >
using BufferPtr = AutoReleaseBuffer<T>

Smart pointer for buffers.

This class will automatically unref a Buffer when going out of scope.

Definition at line 259 of file Buffer.hxx.

Function Documentation

◆ get_buffer_deleter()

template<typename T >
BufferPtr< T > get_buffer_deleter ( Buffer< T > *  b)

Helper function to create a BufferPtr of an appropriate type without having to explicitly specify the template argument.

Example usage: Action foo() { // after an allocate_and_call(barFlow_, STATE(foo)); auto b = get_buffer_deleter(get_allocation_result(barFlow_)); ... // maybe return call_immediately(throw_error); b->data()->qux = 13; // use b regularly as if it was a pointer. barFlow_->send(b.transfer()); }

Parameters
bis the typed raw buffer pointer.
Returns
a buffer deleter object of the respective type.

Definition at line 272 of file Buffer.hxx.

◆ init_main_buffer_pool()

Pool * init_main_buffer_pool ( )

Initializes the main buffer pool.

The first call is not thread safe, later calls are noops. It is recommended to call this one or more times from the static initialization.

Returns
the mainBufferPool instance.

Definition at line 40 of file Buffer.cxx.

Variable Documentation

◆ LARGEST_BUFFERPOOL_BUCKET

const unsigned LARGEST_BUFFERPOOL_BUCKET
extern

Ensures that the largest bucket in the main buffer pool is exactly the size of a GenMessage.

Definition at line 40 of file If.cxx.

◆ mainBufferPool

DynamicPool* mainBufferPool
extern

main buffer pool instance

Definition at line 37 of file Buffer.cxx.