OpenLcbCLib 1.0 Alpha
OpenSource C Library to create OpenLcb/Lcc Nodes
Loading...
Searching...
No Matches
openlcb_buffer_store.h File Reference

Pre-allocated message pool for OpenLCB buffer management. More...

Go to the source code of this file.

Functions

void OpenLcbBufferStore_initialize (void)
 Initializes the buffer store.
 
openlcb_msg_tOpenLcbBufferStore_allocate_buffer (payload_type_enum payload_type)
 Allocates a buffer from the specified pool.
 
void OpenLcbBufferStore_free_buffer (openlcb_msg_t *msg)
 Decrements the reference count; frees the buffer when it reaches zero.
 
void OpenLcbBufferStore_inc_reference_count (openlcb_msg_t *msg)
 Increments the reference count on an allocated buffer.
 
uint16_t OpenLcbBufferStore_basic_messages_allocated (void)
 Returns the number of BASIC messages currently allocated.
 
uint16_t OpenLcbBufferStore_basic_messages_max_allocated (void)
 Returns the peak number of BASIC messages allocated simultaneously.
 
uint16_t OpenLcbBufferStore_datagram_messages_allocated (void)
 Returns the number of DATAGRAM messages currently allocated.
 
uint16_t OpenLcbBufferStore_datagram_messages_max_allocated (void)
 Returns the peak number of DATAGRAM messages allocated simultaneously.
 
uint16_t OpenLcbBufferStore_snip_messages_allocated (void)
 Returns the number of SNIP messages currently allocated.
 
uint16_t OpenLcbBufferStore_snip_messages_max_allocated (void)
 Returns the peak number of SNIP messages allocated simultaneously.
 
uint16_t OpenLcbBufferStore_stream_messages_allocated (void)
 Returns the number of STREAM messages currently allocated.
 
uint16_t OpenLcbBufferStore_stream_messages_max_allocated (void)
 Returns the peak number of STREAM messages allocated simultaneously.
 
void OpenLcbBufferStore_clear_max_allocated (void)
 Resets all peak allocation counters to zero.
 

Detailed Description

Pre-allocated message pool for OpenLCB buffer management.

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.

Provides fixed-size pools for BASIC, DATAGRAM, SNIP, and STREAM message types. All memory is allocated at startup; there is no dynamic allocation at runtime. Reference counting lets the same buffer be held by multiple queues simultaneously. Must be initialized before any other OpenLCB module.

Author
Jim Kueneman
Date
28 Feb 2026

Function Documentation

◆ OpenLcbBufferStore_initialize()

void OpenLcbBufferStore_initialize ( void )
extern

Initializes the buffer store.

Clears all message structures, links payloads, and resets counters. Must be called once at startup before any allocation.

Algorithm:

  1. Clear each message structure
  2. Link each slot to its payload buffer based on pool segment (BASIC, DATAGRAM, SNIP, STREAM)
  3. Reset all allocation and peak counters to zero

◆ OpenLcbBufferStore_allocate_buffer()

openlcb_msg_t * OpenLcbBufferStore_allocate_buffer ( payload_type_enum payload_type)
extern

Allocates a buffer from the specified pool.

Parameters
payload_typepayload_type_enum (BASIC, DATAGRAM, SNIP, or STREAM).
Returns
Pointer to the allocated openlcb_msg_t, or NULL if the pool is exhausted.

Algorithm:

  1. Determine pool segment range from payload_type
  2. Search for first unallocated slot in that range
  3. Clear the message, set reference_count to 1, mark allocated
  4. Update telemetry and return the pointer (or NULL if exhausted)
* @param payload_type Type of buffer requested (BASIC, DATAGRAM, SNIP, or STREAM)
* 
Returns
Pointer to allocated openlcb_msg_t, or NULL if pool exhausted

◆ OpenLcbBufferStore_free_buffer()

void OpenLcbBufferStore_free_buffer ( openlcb_msg_t * msg)
extern

Decrements the reference count; frees the buffer when it reaches zero.

Parameters
msgPointer to the openlcb_msg_t to release (NULL is safe).

Algorithm:

  1. If NULL, return immediately
  2. Decrement reference_count; if still positive, return
  3. Decrement the pool allocation counter and mark the slot as free
* @param msg Pointer to @ref openlcb_msg_t to release (NULL is safe)
* 

◆ OpenLcbBufferStore_inc_reference_count()

void OpenLcbBufferStore_inc_reference_count ( openlcb_msg_t * msg)
extern

Increments the reference count on an allocated buffer.

Parameters
msgPointer to the openlcb_msg_t to share.

◆ OpenLcbBufferStore_basic_messages_allocated()

uint16_t OpenLcbBufferStore_basic_messages_allocated ( void )
extern

Returns the number of BASIC messages currently allocated.

◆ OpenLcbBufferStore_basic_messages_max_allocated()

uint16_t OpenLcbBufferStore_basic_messages_max_allocated ( void )
extern

Returns the peak number of BASIC messages allocated simultaneously.

◆ OpenLcbBufferStore_datagram_messages_allocated()

uint16_t OpenLcbBufferStore_datagram_messages_allocated ( void )
extern

Returns the number of DATAGRAM messages currently allocated.

◆ OpenLcbBufferStore_datagram_messages_max_allocated()

uint16_t OpenLcbBufferStore_datagram_messages_max_allocated ( void )
extern

Returns the peak number of DATAGRAM messages allocated simultaneously.

◆ OpenLcbBufferStore_snip_messages_allocated()

uint16_t OpenLcbBufferStore_snip_messages_allocated ( void )
extern

Returns the number of SNIP messages currently allocated.

◆ OpenLcbBufferStore_snip_messages_max_allocated()

uint16_t OpenLcbBufferStore_snip_messages_max_allocated ( void )
extern

Returns the peak number of SNIP messages allocated simultaneously.

◆ OpenLcbBufferStore_stream_messages_allocated()

uint16_t OpenLcbBufferStore_stream_messages_allocated ( void )
extern

Returns the number of STREAM messages currently allocated.

◆ OpenLcbBufferStore_stream_messages_max_allocated()

uint16_t OpenLcbBufferStore_stream_messages_max_allocated ( void )
extern

Returns the peak number of STREAM messages allocated simultaneously.

◆ OpenLcbBufferStore_clear_max_allocated()

void OpenLcbBufferStore_clear_max_allocated ( void )
extern

Resets all peak allocation counters to zero.


Copyright (c) 2026 Jim Kueneman all rights reserved. See the License