Contents
KosQueueAlloc()
This function is declared in the kos/queue.h
file.
void *KosQueueAlloc(KosQueueHandle queue);
Allocates memory for the new object from the queue
buffer.
If successful, the function returns the pointer to the memory for this object. If the buffer is full, it returns RTL_NULL.
Page topKosQueueCreate()
This function is declared in the kos/queue.h
file.
KosQueueHandle KosQueueCreate(unsigned objCount,
unsigned objSize,
unsigned objAlign,
void *buffer);
This function creates a queue of objects (fifo) and the buffer associated with this queue.
Parameters:
objCount
is the maximum number of objects in the queue.objSize
is the object size (bytes).objAlign
is the object alignment in bytes, and must be a power of two.buffer
is the pointer to the external buffer for objects; if it is set equal to RTL_NULL, the buffer will be allocated by using theKosMemAlloc()
function.
Returns the handle of the created queue and RTL_NULL if there is an error.
Page topKosQueueDestroy()
This function is declared in the kos/queue.h
file.
void KosQueueDestroy(KosQueueHandle queue);
This function deletes the specified queue
and frees its allocated buffer.
KosQueueFlush()
This function is declared in the kos/queue.h
file.
void KosQueueFlush(KosQueueHandle queue);
This function extracts all objects from the specified queue
and frees all the memory occupied by it.
KosQueueFree()
This function is declared in the kos/queue.h
file.
void KosQueueFree(KosQueueHandle queue, void *obj);
This function frees the memory occupied by object obj
in the buffer of the specified queue
.
The obj
pointer can be received by calling the KosQueueAlloc()
or KosQueuePop()
function.
For a usage example, see KosQueuePop()
.
KosQueuePop()
This function is declared in the kos/queue.h
file.
void *KosQueuePop(KosQueueHandle queue, rtl_uint32_t timeout);
This function extracts the object from the start of the specified queue
and returns the pointer to it.
The timeout
parameter determines the behavior of the function if the queue is empty:
- 0 – immediately return RTL_NULL.
- INFINITE_TIMEOUT – lock and wait for a new object in the queue.
- Any other value of
timeout
means that the system is waiting for a new object in the queue for the specifiedtimeout
in milliseconds; when this timeout expires, RTL_NULL is returned.
Example
int GpioEventDispatch(void *context)
{
GpioEvent *event;
GpioDevice *device = context;
rtl_bool proceed = rtl_true;
do {
event = KosQueuePop(device->queue, INFINITE_TIMEOUT);
if (event != RTL_NULL) {
if (event->type == GPIO_EVENT_TYPE_THREAD_ABORT) {
proceed = rtl_false;
} else {
GpioDeliverEvent(device, event);
}
KosQueueFree(device->queue, event);
}
} while (proceed);
KosPutObject(device);
return rcOk;
}
KosQueuePush()
This function is declared in the kos/queue.h
file.
void KosQueuePush(KosQueueHandle queue, void *obj);
Adds the obj
object to the end of the specified queue
.
The obj
pointer can be received by calling the KosQueueAlloc()
or KosQueuePop()
function.