Kohi Game Engine
ring_queue.h File Reference
#include "defines.h"

Go to the source code of this file.

Data Structures

struct  ring_queue
 Represents a ring queue of a particular size. Does not resize dynamically. Naturally, this is a first in, first out structure. More...
 

Typedefs

typedef struct ring_queue ring_queue
 Represents a ring queue of a particular size. Does not resize dynamically. Naturally, this is a first in, first out structure. More...
 

Functions

b8 ring_queue_create (u32 stride, u32 capacity, void *memory, ring_queue *out_queue)
 Creates a new ring queue of the given capacity and stride. More...
 
void ring_queue_destroy (ring_queue *queue)
 Destroys the given queue. If memory was not passed in during creation, it is freed here. More...
 
b8 ring_queue_enqueue (ring_queue *queue, void *value)
 Adds value to queue, if space is available. More...
 
b8 ring_queue_dequeue (ring_queue *queue, void *out_value)
 Attempts to retrieve the next value from the provided queue. More...
 
b8 ring_queue_peek (const ring_queue *queue, void *out_value)
 Attempts to retrieve, but not remove, the next value in the queue, if not empty. More...
 

Typedef Documentation

◆ ring_queue

typedef struct ring_queue ring_queue

Represents a ring queue of a particular size. Does not resize dynamically. Naturally, this is a first in, first out structure.

Function Documentation

◆ ring_queue_create()

b8 ring_queue_create ( u32  stride,
u32  capacity,
void *  memory,
ring_queue out_queue 
)

Creates a new ring queue of the given capacity and stride.

Parameters
strideThe size of each element in bytes.
capacityThe total number of elements to be available in the queue.
memoryThe memory block used to hold the data. Should be the size of stride * capacity. If 0 is passed, a block is automatically allocated and freed upon creation/destruction.
out_queueA pointer to hold the newly created queue.
Returns
True on success; otherwise false.

◆ ring_queue_dequeue()

b8 ring_queue_dequeue ( ring_queue queue,
void *  out_value 
)

Attempts to retrieve the next value from the provided queue.

Parameters
queueA pointer to the queue to retrieve data from.
out_valueA pointer to hold the retrieved value.
Returns
True if success; otherwise false.

◆ ring_queue_destroy()

void ring_queue_destroy ( ring_queue queue)

Destroys the given queue. If memory was not passed in during creation, it is freed here.

Parameters
queueA pointer to the queue to destroy.

◆ ring_queue_enqueue()

b8 ring_queue_enqueue ( ring_queue queue,
void *  value 
)

Adds value to queue, if space is available.

Parameters
queueA pointer to the queue to add data to.
valueThe value to be added.
Returns
True if success; otherwise false.

◆ ring_queue_peek()

b8 ring_queue_peek ( const ring_queue queue,
void *  out_value 
)

Attempts to retrieve, but not remove, the next value in the queue, if not empty.

Parameters
queueA constant pointer to the queue to retrieve data from.
out_valueA pointer to hold the retrieved value.
Returns
True if success; otherwise false.