KasperskyOS Community Edition 1.1
[Topic libkos_queues]

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 top
[Topic kos_queue_alloc]

KosQueueCreate()

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 the KosMemAlloc() function.

Returns the handle of the created queue and RTL_NULL if there is an error.

Page top
[Topic kos_queue_create]

KosQueueDestroy()

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.

Page top
[Topic kos_queue_destroy]

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.

Page top
[Topic kos_queue_flush]

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().

Page top
[Topic kos_queue_free]

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 specified timeout 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;

}

Page top
[Topic kos_queue_pop]

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.

Page top
[Topic kos_queue_push]