Skip to content
«interface»SolidSyslogBufferCircularBufferCore«interface»SolidSyslogMutex

File SolidSyslogCircularBuffer.h

FileList > Core > Interface > SolidSyslogCircularBuffer.h

  • #include "SolidSyslogExternC.h"
  • #include <stddef.h>
  • #include <stdint.h>
  • #include "SolidSyslogDiscardPolicy.h"
  • #include "SolidSyslogTunables.h"

Detailed Description

An in-memory ring Buffer that decouples Log (enqueue) from Service (drain), backed entirely by caller-supplied storage - no allocation of its own.

Records are framed with a uint16 length prefix and stored back-to-back. A record is never split across the ring's end: one that would straddle the wrap point is written whole to the front, leaving a gap that the reader skips via a wrap marker. A full ring applies the injected discard policy: Oldest evicts records from the head to make room, Newest and Halt refuse the record being written. Either loss is reported as SOLIDSYSLOG_CAT_BUFFER_RECORDS_LOST, once per run, with a detail saying which. A record larger than SOLIDSYSLOG_MAX_MESSAGE_SIZE, which SolidSyslog_Log never formats, is rejected outright and reported as SOLIDSYSLOG_CAT_BAD_ARGUMENT. A Read whose buffer is too small for the head record leaves the record in place and reports nothing delivered.

Every enqueue and drain is bracketed by the injected mutex, so the two sides are safe on separate tasks; inject SolidSyslogNullMutex_Get() for single-task use where the lock is pure overhead.

Public Types Documentation

enum

enum {
    SOLIDSYSLOG_CIRCULAR_BUFFER_HEADER_BYTES = sizeof(uint16_t)
};

Public Functions Documentation

SolidSyslogCircularBuffer_Create

In-memory ring Buffer: Log enqueues, Service drains, decoupling the two.

struct SolidSyslogBuffer * SolidSyslogCircularBuffer_Create (
    struct SolidSyslogMutex * mutex,
    uint8_t * ring,
    size_t ringBytes,
    SolidSyslogDiscardPolicyFunction getDiscardPolicy,
    void * discardPolicyContext
) 

The caller supplies the backing ring (ringBytes wide, sized via SOLIDSYSLOG_CIRCULAR_BUFFER_RING_BYTES) and a mutex making the enqueue and drain sides mutually safe when they run on different tasks; inject SolidSyslogNullMutex_Get() for single-task use. Both must outlive the buffer, and the ring is the buffer's alone until Destroy: nothing else may write to it, and its contents are not checked when read back. A NULL mutex or a NULL ring is reported as SOLIDSYSLOG_CAT_BAD_CONFIG and Create returns the shared NullBuffer. Records are length-prefixed and never split across the wrap point (a record that would straddle the end wraps whole to the front).

getDiscardPolicy is asked, with discardPolicyContext, on a write the full ring cannot take, from the task that logs; give it the function the logger has, so the pipeline applies one policy. NULL applies Oldest. Under Oldest the ring drops records from its head until the new one fits, and refuses without evicting a record no empty ring could hold; Newest and Halt refuse the record being written. An exhausted pool falls back to the shared NullBuffer.


SolidSyslogCircularBuffer_Destroy

Release the pool slot; does not free the caller-supplied ring or mutex.

void SolidSyslogCircularBuffer_Destroy (
    struct SolidSyslogBuffer * base
) 


Macro Definition Documentation

SOLIDSYSLOG_CIRCULAR_BUFFER_RING_BYTES

Ring bytes to hold maxMessages worst-case records (each a full SOLIDSYSLOG_MAX_MESSAGE_SIZE payload plus its length prefix).

#define SOLIDSYSLOG_CIRCULAR_BUFFER_RING_BYTES (
    maxMessages
) `((maxMessages) * ( SOLIDSYSLOG_MAX_MESSAGE_SIZE + SOLIDSYSLOG_CIRCULAR_BUFFER_HEADER_BYTES ))`

Smaller messages pack tighter, so this is a capacity floor, not an exact fit.



The documentation for this class was generated from the following file Core/Interface/SolidSyslogCircularBuffer.h