Files | |
file | mbx.c |
Mailbox functions. | |
Defines | |
#define | _mbx_signal(mbx, blckdon) |
#define | MOD_SIZE(indx) ((indx) < mbx->size ? (indx) : (indx) - mbx->size) |
#define | CHK_MBX_MAGIC do { if (!mbx || mbx->magic != RT_MBX_MAGIC) return (CONFIG_RTAI_USE_NEWERR ? RTE_OBJINV : -EINVAL); } while (0) |
#define | MBX_RET(msg_size, retval) (CONFIG_RTAI_USE_NEWERR ? retval : msg_size) |
Functions | |
MODULE_LICENSE ("GPL") | |
static void | mbx_delete_signal (MBX *mbx) |
static void | mbx_signal (MBX *mbx) |
static int | mbx_wait (MBX *mbx, int *fravbs, RT_TASK *rt_current) |
static int | mbx_wait_until (MBX *mbx, int *fravbs, RTIME time, RT_TASK *rt_current) |
static int | mbxput (MBX *mbx, char **msg, int msg_size, int space) |
static int | mbxovrwrput (MBX *mbx, char **msg, int msg_size, int space) |
static int | mbxget (MBX *mbx, char **msg, int msg_size, int space) |
static int | mbxevdrp (MBX *mbx, char **msg, int msg_size, int space) |
RTAI_SYSCALL_MODE int | _rt_mbx_evdrp (MBX *mbx, void *msg, int msg_size, int space) |
Receives bytes as many as possible leaving the message available for another receive. | |
RTAI_SYSCALL_MODE int | rt_typed_mbx_init (MBX *mbx, int size, int type) |
Initializes a fully typed mailbox queueing tasks according to the specified type. | |
int | rt_mbx_init (MBX *mbx, int size) |
Initializes a mailbox. | |
RTAI_SYSCALL_MODE int | rt_mbx_delete (MBX *mbx) |
Deletes a mailbox. | |
RTAI_SYSCALL_MODE int | _rt_mbx_send (MBX *mbx, void *msg, int msg_size, int space) |
Sends a message unconditionally. | |
RTAI_SYSCALL_MODE int | _rt_mbx_send_wp (MBX *mbx, void *msg, int msg_size, int space) |
Sends as many bytes as possible without blocking the calling task. | |
RTAI_SYSCALL_MODE int | _rt_mbx_send_if (MBX *mbx, void *msg, int msg_size, int space) |
Sends a message, only if the whole message can be passed without blocking the calling task. | |
RTAI_SYSCALL_MODE int | _rt_mbx_send_until (MBX *mbx, void *msg, int msg_size, RTIME time, int space) |
Sends a message with absolute timeout. | |
RTAI_SYSCALL_MODE int | _rt_mbx_send_timed (MBX *mbx, void *msg, int msg_size, RTIME delay, int space) |
Sends a message with relative timeout. | |
RTAI_SYSCALL_MODE int | _rt_mbx_receive (MBX *mbx, void *msg, int msg_size, int space) |
Receives a message unconditionally. | |
RTAI_SYSCALL_MODE int | _rt_mbx_receive_wp (MBX *mbx, void *msg, int msg_size, int space) |
Receives bytes as many as possible, without blocking the calling task. | |
RTAI_SYSCALL_MODE int | _rt_mbx_receive_if (MBX *mbx, void *msg, int msg_size, int space) |
Receives a message only if the whole message can be passed without blocking the calling task. | |
RTAI_SYSCALL_MODE int | _rt_mbx_receive_until (MBX *mbx, void *msg, int msg_size, RTIME time, int space) |
Receives a message with absolute timeout. | |
RTAI_SYSCALL_MODE int | _rt_mbx_receive_timed (MBX *mbx, void *msg, int msg_size, RTIME delay, int space) |
Receives a message with relative timeout. | |
RTAI_SYSCALL_MODE int | _rt_mbx_ovrwr_send (MBX *mbx, void *msg, int msg_size, int space) |
Sends a message overwriting what already in the buffer if there is no place for the message. | |
RTAI_SYSCALL_MODE MBX * | _rt_typed_named_mbx_init (unsigned long mbx_name, int size, int qtype) |
Initializes a specifically typed (fifo queued, priority queued or resource queued) mailbox identified by a name. | |
RTAI_SYSCALL_MODE int | rt_named_mbx_delete (MBX *mbx) |
Deletes a named mailbox. | |
int | set_rt_fun_entries (struct rt_native_fun_entry *entry) |
void | reset_rt_fun_entries (struct rt_native_fun_entry *entry) |
static int | recv_blocks (void *mbx) |
static int | send_blocks (void *mbx) |
int | __rtai_mbx_init (void) |
void | __rtai_mbx_exit (void) |
Variables | |
rt_native_fun_entry | rt_mbx_entries [] |
#define _mbx_signal | ( | mbx, | |||
blckdon | ) |
Value:
do { \ unsigned long flags; \ RT_TASK *task; \ flags = rt_global_save_flags_and_cli(); \ if ((task = mbx->waiting_task)) { \ rem_timed_task(task); \ task->blocked_on = blckdon; \ mbx->waiting_task = NULL; \ if (task->state != RT_SCHED_READY && (task->state &= ~(RT_SCHED_MBXSUSP | RT_SCHED_DELAYED)) == RT_SCHED_READY) { \ enq_ready_task(task); \ RT_SCHEDULE(task, rtai_cpuid()); \ } \ } \ rt_global_restore_flags(flags); \ } while (0)
Definition at line 43 of file mbx.c.
Referenced by mbx_delete_signal(), and mbx_signal().
#define CHK_MBX_MAGIC do { if (!mbx || mbx->magic != RT_MBX_MAGIC) return (CONFIG_RTAI_USE_NEWERR ? RTE_OBJINV : -EINVAL); } while (0) |
Definition at line 275 of file mbx.c.
Referenced by _rt_mbx_ovrwr_send(), _rt_mbx_receive(), _rt_mbx_receive_if(), _rt_mbx_receive_until(), _rt_mbx_receive_wp(), _rt_mbx_send(), _rt_mbx_send_if(), _rt_mbx_send_until(), _rt_mbx_send_wp(), and rt_mbx_delete().
#define MBX_RET | ( | msg_size, | |||
retval | ) | (CONFIG_RTAI_USE_NEWERR ? retval : msg_size) |
Definition at line 278 of file mbx.c.
Referenced by _rt_mbx_receive(), _rt_mbx_receive_until(), _rt_mbx_send(), and _rt_mbx_send_until().
#define MOD_SIZE | ( | indx | ) | ((indx) < mbx->size ? (indx) : (indx) - mbx->size) |
void __rtai_mbx_exit | ( | void | ) |
Definition at line 963 of file mbx.c.
References reset_rt_fun_entries(), rt_mbx_entries, RT_POLL_MBX_RECV, RT_POLL_MBX_SEND, and rt_poll_ofstfun.
Here is the call graph for this function:
int __rtai_mbx_init | ( | void | ) |
Definition at line 956 of file mbx.c.
References recv_blocks(), rt_mbx_entries, RT_POLL_MBX_RECV, RT_POLL_MBX_SEND, rt_poll_ofstfun, send_blocks(), and set_rt_fun_entries().
Here is the call graph for this function:
RTAI_SYSCALL_MODE int _rt_mbx_evdrp | ( | MBX * | mbx, | |
void * | msg, | |||
int | msg_size, | |||
int | space | |||
) |
Receives bytes as many as possible leaving the message available for another receive.
rt_mbx_evdrp receives at most msg_size of bytes of message from the mailbox mbx and then returns immediately. Does what rt_mbx_receive_wp does while keeping the message in the mailbox buffer. Useful if one needs to just preview the mailbox content, without actually receiving it.
mbx | is a pointer to a user allocated mailbox structure. | |
msg | points to a buffer provided by the caller. | |
msg_size | corresponds to the size of the message to be received. |
Definition at line 269 of file mbx.c.
References mbxevdrp().
Here is the call graph for this function:
RTAI_SYSCALL_MODE int _rt_mbx_ovrwr_send | ( | MBX * | mbx, | |
void * | msg, | |||
int | msg_size, | |||
int | space | |||
) |
Sends a message overwriting what already in the buffer if there is no place for the message.
rt_mbx_ovrwr_send sends the message msg of msg_size bytes to the mailbox mbx overwriting what already in the mailbox buffer if there is no place for the message. Useful for logging purposes. It returns immediately and the caller is never blocked.
Definition at line 823 of file mbx.c.
References CHK_MBX_MAGIC, flags, mbx_signal(), mbxovrwrput(), and rt_sem_signal().
Here is the call graph for this function:
RTAI_SYSCALL_MODE int _rt_mbx_receive | ( | MBX * | mbx, | |
void * | msg, | |||
int | msg_size, | |||
int | space | |||
) |
Receives a message unconditionally.
rt_mbx_receive receives a message of msg_size bytes from the mailbox mbx. The caller will be blocked until all bytes of the message arrive or an error occurs.
mbx | is a pointer to a user allocated mailbox structure. | |
msg | points to a buffer provided by the caller. | |
msg_size | corresponds to the size of the message to be received. |
Definition at line 619 of file mbx.c.
References CHK_MBX_MAGIC, MBX_RET, mbx_signal(), mbx_wait(), mbxget(), rt_sem_signal(), and rt_sem_wait().
Referenced by rt_get_net_rpc_ret().
Here is the call graph for this function:
RTAI_SYSCALL_MODE int _rt_mbx_receive_if | ( | MBX * | mbx, | |
void * | msg, | |||
int | msg_size, | |||
int | space | |||
) |
Receives a message only if the whole message can be passed without blocking the calling task.
rt_mbx_receive_if receives a message from the mailbox mbx if the whole message of msg_size bytes is available immediately.
mbx | is a pointer to a user allocated mailbox structure. | |
msg | points to a buffer provided by the caller. | |
msg_size | corresponds to the size of the message to be received. |
Definition at line 708 of file mbx.c.
References CHK_MBX_MAGIC, flags, mbx_signal(), mbxget(), and rt_sem_signal().
Here is the call graph for this function:
RTAI_SYSCALL_MODE int _rt_mbx_receive_timed | ( | MBX * | mbx, | |
void * | msg, | |||
int | msg_size, | |||
RTIME | delay, | |||
int | space | |||
) |
Receives a message with relative timeout.
rt_mbx_receive_timed receives a message of msg_size bytes from the mailbox mbx. The caller will be blocked until all bytes of the message arrive, timeout expires or an error occurs.
mbx | is a pointer to a user allocated mailbox structure. | |
msg | points to a buffer provided by the caller. | |
msg_size | corresponds to the size of the message received. | |
delay | is the timeout value relative to the current time. |
Definition at line 804 of file mbx.c.
References _rt_mbx_receive_until().
Here is the call graph for this function:
RTAI_SYSCALL_MODE int _rt_mbx_receive_until | ( | MBX * | mbx, | |
void * | msg, | |||
int | msg_size, | |||
RTIME | time, | |||
int | space | |||
) |
Receives a message with absolute timeout.
rt_mbx_receive_until receives a message of msg_size bytes from the mailbox mbx. The caller will be blocked until all bytes of the message arrive, timeout expires or an error occurs.
mbx | is a pointer to a user allocated mailbox structure. | |
msg | points to a buffer provided by the caller. | |
msg_size | corresponds to the size of the message received. | |
time | is an absolute value of the timeout. |
Definition at line 756 of file mbx.c.
References CHK_MBX_MAGIC, MBX_RET, mbx_signal(), mbx_wait_until(), mbxget(), rt_sem_signal(), and rt_sem_wait_until().
Referenced by _rt_mbx_receive_timed().
Here is the call graph for this function:
RTAI_SYSCALL_MODE int _rt_mbx_receive_wp | ( | MBX * | mbx, | |
void * | msg, | |||
int | msg_size, | |||
int | space | |||
) |
Receives bytes as many as possible, without blocking the calling task.
rt_mbx_receive_wp receives at most msg_size of bytes of message from the mailbox mbx then returns immediately.
mbx | is a pointer to a user allocated mailbox structure. | |
msg | points to a buffer provided by the caller. | |
msg_size | corresponds to the size of the message to be received. |
Definition at line 662 of file mbx.c.
References CHK_MBX_MAGIC, flags, mbx_signal(), mbxget(), and rt_sem_signal().
Here is the call graph for this function:
RTAI_SYSCALL_MODE int _rt_mbx_send | ( | MBX * | mbx, | |
void * | msg, | |||
int | msg_size, | |||
int | space | |||
) |
Sends a message unconditionally.
rt_mbx_send sends a message msg of msg_size bytes to the mailbox mbx. The caller will be blocked until the whole message is copied into the mailbox or an error occurs. Even if the message can be sent in a single shot, the sending task can be blocked if there is a task of higher priority waiting to receive from the mailbox.
mbx | is a pointer to a user allocated mailbox structure. | |
msg | corresponds to the message to be sent. | |
msg_size | is the size of the message. |
Definition at line 416 of file mbx.c.
References CHK_MBX_MAGIC, MBX_RET, mbx_signal(), mbx_wait(), mbxput(), rt_sem_signal(), and rt_sem_wait().
Here is the call graph for this function:
RTAI_SYSCALL_MODE int _rt_mbx_send_if | ( | MBX * | mbx, | |
void * | msg, | |||
int | msg_size, | |||
int | space | |||
) |
Sends a message, only if the whole message can be passed without blocking the calling task.
rt_mbx_send_if tries to atomically send the message msg of msg_size bytes to the mailbox mbx. It returns immediately and the caller is never blocked.
Definition at line 498 of file mbx.c.
References CHK_MBX_MAGIC, flags, mbx_signal(), mbxput(), and rt_sem_signal().
Here is the call graph for this function:
RTAI_SYSCALL_MODE int _rt_mbx_send_timed | ( | MBX * | mbx, | |
void * | msg, | |||
int | msg_size, | |||
RTIME | delay, | |||
int | space | |||
) |
Sends a message with relative timeout.
rt_mbx_send_timed send a message msg of msg_size bytes to the mailbox mbx. The caller will be blocked until all bytes of message is enqueued, timeout expires or an error occurs.
mbx | is a pointer to a user allocated mailbox structure. | |
msg | is the message to be sent. | |
msg_size | corresponds to the size of the message. | |
delay | is the timeout value relative to the current time. |
Definition at line 594 of file mbx.c.
References _rt_mbx_send_until().
Here is the call graph for this function:
RTAI_SYSCALL_MODE int _rt_mbx_send_until | ( | MBX * | mbx, | |
void * | msg, | |||
int | msg_size, | |||
RTIME | time, | |||
int | space | |||
) |
Sends a message with absolute timeout.
rt_mbx_send_until sends a message msg of msg_size bytes to the mailbox mbx. The caller will be blocked until all bytes of message is enqueued, timeout expires or an error occurs.
mbx | is a pointer to a user allocated mailbox structure. | |
msg | is the message to be sent. | |
msg_size | corresponds to the size of the message. | |
time | is an absolute value for the timeout. |
Definition at line 546 of file mbx.c.
References CHK_MBX_MAGIC, MBX_RET, mbx_signal(), mbx_wait_until(), mbxput(), rt_sem_signal(), and rt_sem_wait_until().
Referenced by _rt_mbx_send_timed().
Here is the call graph for this function:
RTAI_SYSCALL_MODE int _rt_mbx_send_wp | ( | MBX * | mbx, | |
void * | msg, | |||
int | msg_size, | |||
int | space | |||
) |
Sends as many bytes as possible without blocking the calling task.
rt_mbx_send_wp atomically sends as many bytes of message msg as possible to the mailbox mbx then returns immediately.
mbx | is a pointer to a user allocated mailbox structure. | |
msg | corresponds to the message to be sent. | |
msg_size | is the size of the message. |
Definition at line 457 of file mbx.c.
References CHK_MBX_MAGIC, flags, mbx_signal(), mbxput(), and rt_sem_signal().
Here is the call graph for this function:
RTAI_SYSCALL_MODE MBX* _rt_typed_named_mbx_init | ( | unsigned long | mbx_name, | |
int | size, | |||
int | qtype | |||
) |
Initializes a specifically typed (fifo queued, priority queued or resource queued) mailbox identified by a name.
_rt_typed_named_mbx_init initializes a mailbox of type qtype and size size identified by name. Named mailboxed are useful for use among different processes, kernel/user space and in distributed applications, see netrpc.
mbx_name | is the mailbox name; since it can be a clumsy identifier, services are provided to convert 6 characters identifiers to unsigned long (see nam2num()). | |
size | corresponds to the size of the mailbox. | |
qtype | corresponds to the queueing policy: FIFO_Q, PRIO_Q or RES_Q. |
Definition at line 874 of file mbx.c.
References IS_MBX, rt_free(), rt_get_adr_cnt(), rt_malloc(), rt_mbx_delete(), rt_register(), and rt_typed_mbx_init().
Here is the call graph for this function:
static void mbx_delete_signal | ( | MBX * | mbx | ) | [static] |
Definition at line 60 of file mbx.c.
References _mbx_signal, and RTP_OBJREM.
Referenced by rt_mbx_delete().
static void mbx_signal | ( | MBX * | mbx | ) | [static] |
Definition at line 70 of file mbx.c.
References flags, RT_SCHED_MBXSUSP, rt_schedule(), and unlikely.
Here is the call graph for this function:
Definition at line 92 of file mbx.c.
References flags, likely, RT_SCHED_DELAYED, RT_SCHED_MBXSUSP, rt_schedule(), rt_smp_time_h, RTE_OBJREM, RTE_TIMOUT, RTE_UNBLKD, RTP_HIGERR, RTP_UNBLKD, and unlikely.
Referenced by _rt_mbx_receive_until(), and _rt_mbx_send_until().
Here is the call graph for this function:
static int mbxevdrp | ( | MBX * | mbx, | |
char ** | msg, | |||
int | msg_size, | |||
int | space | |||
) | [static] |
static int mbxget | ( | MBX * | mbx, | |
char ** | msg, | |||
int | msg_size, | |||
int | space | |||
) | [static] |
Definition at line 196 of file mbx.c.
References flags, MOD_SIZE, rt_spin_lock_irqsave(), and rt_spin_unlock_irqrestore.
Referenced by _rt_mbx_receive(), _rt_mbx_receive_if(), _rt_mbx_receive_until(), and _rt_mbx_receive_wp().
Here is the call graph for this function:
static int mbxovrwrput | ( | MBX * | mbx, | |
char ** | msg, | |||
int | msg_size, | |||
int | space | |||
) | [static] |
Definition at line 147 of file mbx.c.
References flags, MOD_SIZE, rt_spin_lock_irqsave(), and rt_spin_unlock_irqrestore.
Referenced by _rt_mbx_ovrwr_send().
Here is the call graph for this function:
static int mbxput | ( | MBX * | mbx, | |
char ** | msg, | |||
int | msg_size, | |||
int | space | |||
) | [static] |
Definition at line 119 of file mbx.c.
References flags, MOD_SIZE, rt_spin_lock_irqsave(), and rt_spin_unlock_irqrestore.
Referenced by _rt_mbx_send(), _rt_mbx_send_if(), _rt_mbx_send_until(), _rt_mbx_send_wp(), and mbx_send_if().
Here is the call graph for this function:
MODULE_LICENSE | ( | "GPL" | ) |
static int recv_blocks | ( | void * | mbx | ) | [static] |
void reset_rt_fun_entries | ( | struct rt_native_fun_entry * | entry | ) |
RTAI_SYSCALL_MODE int rt_mbx_delete | ( | MBX * | mbx | ) |
Deletes a mailbox.
rt_mbx_delete removes a mailbox previously created with rt_mbx_init().
mbx | is the pointer to the structure used in the corresponding call to rt_mbx_init. |
Definition at line 377 of file mbx.c.
References CHK_MBX_MAGIC, mbx_delete_signal(), rt_free(), rt_sem_delete(), and RTE_OBJREM.
Here is the call graph for this function:
int rt_mbx_init | ( | MBX * | mbx, | |
int | size | |||
) |
Initializes a mailbox.
rt_mbx_init initializes a mailbox of size size. mbx must point to a user allocated MBX structure. Using mailboxes is a flexible method for inter task communications. Tasks are allowed to send arbitrarily sized messages by using any mailbox buffer size. There is even no need to use a buffer sized at least as the largest message you envisage, even if efficiency is likely to suffer from such a decision. However if you expect a message larger than the average message size very rarely you can use a smaller buffer without much loss of efficiency. In such a way you can set up your own mailbox usage protocol, e.g. using fix sized messages with a buffer that is an integer multiple of such a size guarantees maximum efficiency by having each message sent/received atomically to/from the mailbox. Multiple senders and receivers are allowed and each will get the service it requires in turn, according to its priority. Thus mailboxes provide a flexible mechanism to allow you to freely implement your own policy.
rt_mbx_init is equivalent to rt_typed_mbx_init(mbx, size, PRIO_Q).
mbx | is a pointer to a user allocated mailbox structure. | |
size | corresponds to the size of the mailbox. |
Definition at line 357 of file mbx.c.
References PRIO_Q, and rt_typed_mbx_init().
Here is the call graph for this function:
RTAI_SYSCALL_MODE int rt_named_mbx_delete | ( | MBX * | mbx | ) |
Deletes a named mailbox.
rt_named_mbx_delete removes a mailbox previously created with _rt_typed_named_mbx_init().
mbx | is the pointer to the structure returned by a corresponding call to _rt_typed_named_mbx_init. |
Definition at line 913 of file mbx.c.
References rt_drg_on_adr_cnt(), rt_free(), and rt_mbx_delete().
Here is the call graph for this function:
RTAI_SYSCALL_MODE int rt_typed_mbx_init | ( | MBX * | mbx, | |
int | size, | |||
int | type | |||
) |
Initializes a fully typed mailbox queueing tasks according to the specified type.
rt_typed_mbx_init initializes a mailbox of size size. mbx must point to a user allocated MBX structure. Tasks are queued in FIFO order (FIFO_Q), priority order (PRIO_Q) or resource order (RES_Q).
mbx | is a pointer to a user allocated mailbox structure. | |
size | corresponds to the size of the mailbox. | |
type | corresponds to the queueing policy: FIFO_Q, PRIO_Q or RES_Q. |
Definition at line 301 of file mbx.c.
References BIN_SEM, rt_malloc(), RT_MBX_MAGIC, and rt_typed_sem_init().
Here is the call graph for this function:
static int send_blocks | ( | void * | mbx | ) | [static] |
int set_rt_fun_entries | ( | struct rt_native_fun_entry * | entry | ) |
struct rt_native_fun_entry rt_mbx_entries[] |
Initial value:
{ { { 0, rt_typed_mbx_init }, TYPED_MBX_INIT }, { { 0, rt_mbx_delete }, MBX_DELETE }, { { 1, _rt_mbx_send }, MBX_SEND }, { { 1, _rt_mbx_send_wp }, MBX_SEND_WP }, { { 1, _rt_mbx_send_if }, MBX_SEND_IF }, { { 1, _rt_mbx_send_until }, MBX_SEND_UNTIL }, { { 1, _rt_mbx_send_timed }, MBX_SEND_TIMED }, { { 1, _rt_mbx_ovrwr_send }, MBX_OVRWR_SEND }, { { 1, _rt_mbx_evdrp }, MBX_EVDRP }, { { 1, _rt_mbx_receive }, MBX_RECEIVE }, { { 1, _rt_mbx_receive_wp }, MBX_RECEIVE_WP }, { { 1, _rt_mbx_receive_if }, MBX_RECEIVE_IF }, { { 1, _rt_mbx_receive_until }, MBX_RECEIVE_UNTIL }, { { 1, _rt_mbx_receive_timed }, MBX_RECEIVE_TIMED }, { { 0, _rt_typed_named_mbx_init }, NAMED_MBX_INIT }, { { 0, rt_named_mbx_delete }, NAMED_MBX_DELETE }, { { 0, 0 }, 000 } }
Definition at line 929 of file mbx.c.
Referenced by __rtai_mbx_exit(), and __rtai_mbx_init().