Xenomai API
2.6.5
|
Files | |
file | queue.c |
This file is part of the Xenomai project. | |
Functions | |
int | rt_queue_create (RT_QUEUE *q, const char *name, size_t poolsize, size_t qlimit, int mode) |
Create a message queue. More... | |
int | rt_queue_delete (RT_QUEUE *q) |
Delete a message queue. More... | |
void * | rt_queue_alloc (RT_QUEUE *q, size_t size) |
Allocate a message queue buffer. More... | |
int | rt_queue_free (RT_QUEUE *q, void *buf) |
Free a message queue buffer. More... | |
int | rt_queue_send (RT_QUEUE *q, void *mbuf, size_t size, int mode) |
Send a message to a queue. More... | |
int | rt_queue_write (RT_QUEUE *q, const void *buf, size_t size, int mode) |
Write a message to a queue. More... | |
ssize_t | rt_queue_receive (RT_QUEUE *q, void **bufp, RTIME timeout) |
Receive a message from a queue. More... | |
ssize_t | rt_queue_receive_until (RT_QUEUE *q, void **bufp, RTIME timeout) |
Receive a message from a queue (with absolute timeout date). More... | |
ssize_t | rt_queue_read (RT_QUEUE *q, void *buf, size_t size, RTIME timeout) |
Read a message from a queue. More... | |
ssize_t | rt_queue_read_until (RT_QUEUE *q, void *buf, size_t size, RTIME timeout) |
Read a message from a queue (with absolute timeout date). More... | |
int | rt_queue_flush (RT_QUEUE *q) |
Flush a message queue. More... | |
int | rt_queue_inquire (RT_QUEUE *q, RT_QUEUE_INFO *info) |
Inquire about a message queue. More... | |
int | rt_queue_bind (RT_QUEUE *q, const char *name, RTIME timeout) |
Bind to a shared message queue. More... | |
int | rt_queue_unbind (RT_QUEUE *q) |
Unbind from a shared message queue. More... | |
Queue services.
Message queueing is a method by which real-time tasks can exchange or pass data through a Xenomai-managed queue of messages. Messages can vary in length and be assigned different types or usages. A message queue can be created by one task and used by multiple tasks that send and/or receive messages to the queue.
This implementation is based on a zero-copy scheme for message buffers. Message buffer pools are built over the nucleus's heap objects, which in turn provide the needed support for exchanging messages between kernel and user-space using direct memory mapping.
void* rt_queue_alloc | ( | RT_QUEUE * | q, |
size_t | size | ||
) |
Allocate a message queue buffer.
This service allocates a message buffer from the queue's internal pool which can be subsequently filled by the caller then passed to rt_queue_send() for sending.
q | The descriptor address of the affected queue. |
size | The requested size in bytes of the buffer. Zero is an acceptable value, meaning that the message will not carry any payload data; the receiver will thus receive a zero-sized message. |
Environments:
This service can be called from:
Rescheduling: never.
References xnheap_alloc().
Referenced by rt_queue_write().
int rt_queue_bind | ( | RT_QUEUE * | q, |
const char * | name, | ||
RTIME | timeout | ||
) |
Bind to a shared message queue.
This user-space only service retrieves the uniform descriptor of a given shared Xenomai message queue identified by its symbolic name. If the queue does not exist on entry, this service blocks the caller until a queue of the given name is created.
name | A valid NULL-terminated name which identifies the queue to bind to. |
q | The address of a queue descriptor retrieved by the operation. Contents of this memory is undefined upon failure. |
timeout | The number of clock ticks to wait for the registration to occur (see note). Passing TM_INFINITE causes the caller to block indefinitely until the object is registered. Passing TM_NONBLOCK causes the service to return immediately without waiting if the object is not registered on entry. |
Environments:
This service can be called from:
Rescheduling: always unless the request is immediately satisfied or timeout specifies a non-blocking operation.
int rt_queue_create | ( | RT_QUEUE * | q, |
const char * | name, | ||
size_t | poolsize, | ||
size_t | qlimit, | ||
int | mode | ||
) |
Create a message queue.
Create a message queue object that allows multiple tasks to exchange data through the use of variable-sized messages. A message queue is created empty. Message queues can be local to the kernel space, or shared between kernel and user-space.
This service needs the special character device /dev/rtheap (10,254) when called from user-space tasks.
q | The address of a queue descriptor Xenomai will use to store the queue-related data. This descriptor must always be valid while the message queue is active therefore it must be allocated in permanent memory. |
name | An ASCII string standing for the symbolic name of the queue. When non-NULL and non-empty, this string is copied to a safe place into the descriptor, and passed to the registry package if enabled for indexing the created queue. Shared queues must be given a valid name. |
poolsize | The size (in bytes) of the message buffer pool which is going to be pre-allocated to the queue. Message buffers will be claimed and released to this pool. The buffer pool memory is not extensible, so this value must be compatible with the highest message pressure that could be expected. |
qlimit | This parameter allows to limit the maximum number of messages which can be queued at any point in time. Sending to a full queue begets an error. The special value Q_UNLIMITED can be passed to specify an unlimited amount. |
mode | The queue creation mode. The following flags can be OR'ed into this bitmask, each of them affecting the new queue: |
Environments:
This service can be called from:
Rescheduling: possible.
References rt_queue_delete(), xnheap_init(), xnheap_set_label(), xnregistry_enter(), and xnsynch_init().
int rt_queue_delete | ( | RT_QUEUE * | q | ) |
Delete a message queue.
Destroy a message queue and release all the tasks currently pending on it. A queue exists in the system since rt_queue_create() has been called to create it, so this service must be called in order to destroy it afterwards.
q | The descriptor address of the affected queue. |
Environments:
This service can be called from:
Rescheduling: possible.
Referenced by rt_queue_create().
int rt_queue_flush | ( | RT_QUEUE * | q | ) |
Flush a message queue.
This service discards all unread messages from a message queue.
q | The descriptor address of the affected queue. |
Environments:
This service can be called from:
Rescheduling: never.
References rt_queue_free().
int rt_queue_free | ( | RT_QUEUE * | q, |
void * | buf | ||
) |
Free a message queue buffer.
This service releases a message buffer returned by rt_queue_receive() to the queue's internal pool.
q | The descriptor address of the affected queue. |
buf | The address of the message buffer to free. Even zero-sized messages carrying no payload data must be freed, since they are assigned a valid memory space to store internal information. |
Environments:
This service can be called from:
Rescheduling: never.
References xnheap_test_and_free().
Referenced by rt_queue_flush().
int rt_queue_inquire | ( | RT_QUEUE * | q, |
RT_QUEUE_INFO * | info | ||
) |
Inquire about a message queue.
Return various information about the status of a given queue.
q | The descriptor address of the inquired queue. |
info | The address of a structure the queue information will be written to. |
Environments:
This service can be called from:
Rescheduling: never.
ssize_t rt_queue_read | ( | RT_QUEUE * | q, |
void * | buf, | ||
size_t | size, | ||
RTIME | timeout | ||
) |
Read a message from a queue.
This service retrieves the next message available from the given queue. Unless otherwise specified, the caller is blocked for a given amount of time if no message is immediately available on entry. This services differs from rt_queue_receive() in that it copies back the payload data to a user-defined memory area, instead of returning a pointer to the message buffer holding such data.
q | The descriptor address of the message queue to read from. |
buf | A pointer to a memory area which will be written upon success with the message contents. The internal message buffer conveying the data is automatically freed by this call. |
size | The length in bytes of the memory area pointed to by buf. Messages larger than size are truncated appropriately. |
timeout | The number of clock ticks to wait for a message to arrive (see note). Passing TM_INFINITE causes the caller to block indefinitely until some message is eventually available. Passing TM_NONBLOCK causes the service to return immediately without waiting if no message is available on entry. |
Environments:
This service can be called from:
Rescheduling: always unless the request is immediately satisfied or timeout specifies a non-blocking operation.
References pthread_setcanceltype().
ssize_t rt_queue_read_until | ( | RT_QUEUE * | q, |
void * | buf, | ||
size_t | size, | ||
RTIME | timeout | ||
) |
Read a message from a queue (with absolute timeout date).
This service retrieves the next message available from the given queue. Unless otherwise specified, the caller is blocked for a given amount of time if no message is immediately available on entry. This services differs from rt_queue_receive() in that it copies back the payload data to a user-defined memory area, instead of returning a pointer to the message buffer holding such data.
q | The descriptor address of the message queue to read from. |
buf | A pointer to a memory area which will be written upon success with the message contents. The internal message buffer conveying the data is automatically freed by this call. |
size | The length in bytes of the memory area pointed to by buf. Messages larger than size are truncated appropriately. |
timeout | The absolute date specifying a time limit to wait for a message to arrive (see note). Passing TM_INFINITE causes the caller to block indefinitely until some message is eventually available. Passing TM_NONBLOCK causes the service to return immediately without waiting if no message is available on entry. |
Environments:
This service can be called from:
Rescheduling: always unless the request is immediately satisfied or timeout specifies a non-blocking operation.
References pthread_setcanceltype().
ssize_t rt_queue_receive | ( | RT_QUEUE * | q, |
void ** | bufp, | ||
RTIME | timeout | ||
) |
Receive a message from a queue.
This service retrieves the next message available from the given queue. Unless otherwise specified, the caller is blocked for a given amount of time if no message is immediately available on entry.
q | The descriptor address of the message queue to receive from. |
bufp | A pointer to a memory location which will be written upon success with the address of the received message. Once consumed, the message space should be freed using rt_queue_free(). |
timeout | The number of clock ticks to wait for a message to arrive (see note). Passing TM_INFINITE causes the caller to block indefinitely until some message is eventually available. Passing TM_NONBLOCK causes the service to return immediately without waiting if no message is available on entry. |
Environments:
This service can be called from:
Rescheduling: always unless the request is immediately satisfied or timeout specifies a non-blocking operation.
References pthread_setcanceltype().
ssize_t rt_queue_receive_until | ( | RT_QUEUE * | q, |
void ** | bufp, | ||
RTIME | timeout | ||
) |
Receive a message from a queue (with absolute timeout date).
This service retrieves the next message available from the given queue. Unless otherwise specified, the caller is blocked for a given amount of time if no message is immediately available on entry.
q | The descriptor address of the message queue to receive from. |
bufp | A pointer to a memory location which will be written upon success with the address of the received message. Once consumed, the message space should be freed using rt_queue_free(). |
timeout | The absolute date specifying a time limit to wait for a message to arrive (see note). Passing TM_INFINITE causes the caller to block indefinitely until some message is eventually available. Passing TM_NONBLOCK causes the service to return immediately without waiting if no message is available on entry. |
Environments:
This service can be called from:
Rescheduling: always unless the request is immediately satisfied or timeout specifies a non-blocking operation.
References pthread_setcanceltype().
int rt_queue_send | ( | RT_QUEUE * | q, |
void * | mbuf, | ||
size_t | size, | ||
int | mode | ||
) |
Send a message to a queue.
This service sends a complete message to a given queue. The message must have been allocated by a previous call to rt_queue_alloc().
q | The descriptor address of the message queue to send to. |
mbuf | The address of the message buffer to be sent. The message buffer must have been allocated using the rt_queue_alloc() service. Once passed to rt_queue_send(), the memory pointed to by mbuf is no more under the control of the sender and thus should not be referenced by it anymore; deallocation of this memory must be handled on the receiving side. |
size | The size in bytes of the message. Zero is a valid value, in which case an empty message will be sent. |
mode | A set of flags affecting the operation: |
Environments:
This service can be called from:
Rescheduling: possible.
References pthread_setcanceltype(), xnpod_schedule(), and xnsynch_wakeup_one_sleeper().
Referenced by rt_queue_write().
int rt_queue_unbind | ( | RT_QUEUE * | q | ) |
Unbind from a shared message queue.
This user-space only service unbinds the calling task from the message queue object previously retrieved by a call to rt_queue_bind().
Unbinding from a message queue when it is no more needed is especially important in order to properly release the mapping resources used to attach the shared queue memory to the caller's address space.
q | The address of a queue descriptor to unbind from. |
This service can be called from:
Rescheduling: never.
int rt_queue_write | ( | RT_QUEUE * | q, |
const void * | buf, | ||
size_t | size, | ||
int | mode | ||
) |
Write a message to a queue.
This service writes a complete message to a given queue. This service differs from rt_queue_send() in that it accepts a pointer to the raw data to be sent, instead of a canned message buffer.
q | The descriptor address of the message queue to write to. |
buf | The address of the message data to be written to the queue. A message buffer will be allocated internally to convey the data. |
size | The size in bytes of the message data. Zero is a valid value, in which case an empty message will be sent. |
mode | A set of flags affecting the operation: |
Environments:
This service can be called from:
Rescheduling: possible.
References pthread_setcanceltype(), rt_queue_alloc(), and rt_queue_send().