OSLIB Objects FIFOs

Objects FIFOs implements in an elegant way a simple use case, sending fixed-size objects from one end to another of a FIFO.

  • No dynamic allocation.
  • Copy-less operations.
  • Able to work from thread and/or ISR context.

The Objects FIFO

This object is an aggregation of two other objects present in OSLIB:

  1. A guarded pool allocator, used for storing the objects to be transferred.
  2. A mailbox as FIFO structure.

Objects FIFO

Operations

Four basic operations are defined:

  • Take, allocates an object from the guarded pool, waiting if an object is not yet available.
  • Send, sends the allocated object through the mailbox.
  • Receive, receives an object from the mailbox.
  • Return, returns a received object from the pool.

Objects FIFO Operations

Note that the pool and the mailbox have the same size so can accommodate the same number of objects, this means:

  • Take can wait if the guarded pool is currently empty (or fail if called from an ISR where it is not possible to wait).
  • Send never waits because there is always enough space in the mailbox by design.
  • Receive can wait if the mailbox is empty (or fail if called from an ISR where it is not possible to wait).
  • Return never waits by design.

Also note that objects are not copied into the mailbox, the mailbox just transports a pointer to the object, the object itself is static, it does not move.

Objects FIFOs API

objects_fifo_t Type of an objects FIFO object.
chFifoObjectInit() Initializes an objects FIFO object of type objects_fifo_t.
chFifoObjectInitAligned() Initializes an objects FIFO object of type objects_fifo_t with alignment constraints.
chFifoTakeObjectTimeout() Takes a free object with timeout.
chFifoTakeObjectTimeoutS() Takes a free object with timeout (S-Class variant).
chFifoTakeObjectI() Takes a free object (I-Class variant).
chFifoReturnObject() Returns an object to the pool.
chFifoReturnObjectS() Returns an object to the pool (S-Class variant).
chFifoReturnObjectI() Returns an object to the pool (I-Class variant).
chFifoSendObject() Sends an object through the mailbox.
chFifoSendObjectS() Sends an object through the mailbox (S-Class variant).
chFifoSendObjectI() Sends an object through the mailbox (I-Class variant).
chFifoSendObjectAhead() Sends an object through the mailbox with priority.
chFifoSendObjectAheadS() Sends an object through the mailbox with priority (S-Class variant).
chFifoSendObjectAheadI() Sends an object through the mailbox with priority (I-Class variant).
chFifoReceiveObjectTimeout() Receives an object from the mailbox with timeout.
chFifoReceiveObjectTimeoutS() Receives an object from the mailbox with timeout (S-Class variant).
chFifoReceiveObjectI() Receives an object from the mailbox (I-Class variant).