Xenomai  3.0.5
Synchronous I/O multiplexing

This module implements the services needed for implementing the POSIX select() service, or any other event multiplexing services. More...

Collaboration diagram for Synchronous I/O multiplexing:

Functions

void xnselect_init (struct xnselect *select_block)
 Initialize a struct xnselect structure. More...
 
static int xnselect_signal (struct xnselect *select_block, unsigned int state)
 Signal a file descriptor state change. More...
 
void xnselect_destroy (struct xnselect *select_block)
 Destroy the xnselect structure associated with a file descriptor. More...
 
int xnselector_init (struct xnselector *selector)
 Initialize a selector structure. More...
 
int xnselect (struct xnselector *selector, fd_set *out_fds[XNSELECT_MAX_TYPES], fd_set *in_fds[XNSELECT_MAX_TYPES], int nfds, xnticks_t timeout, xntmode_t timeout_mode)
 Check the state of a number of file descriptors, wait for a state change if no descriptor is ready. More...
 
void xnselector_destroy (struct xnselector *selector)
 Destroy a selector block. More...
 
int xnselect_bind (struct xnselect *select_block, struct xnselect_binding *binding, struct xnselector *selector, unsigned type, unsigned index, unsigned state)
 Bind a file descriptor (represented by its xnselect structure) to a selector block. More...
 

Detailed Description

This module implements the services needed for implementing the POSIX select() service, or any other event multiplexing services.

Following the implementation of the posix select service, this module defines three types of events:

It works by defining two structures:

Function Documentation

◆ xnselect()

int xnselect ( struct xnselector *  selector,
fd_set *  out_fds[XNSELECT_MAX_TYPES],
fd_set *  in_fds[XNSELECT_MAX_TYPES],
int  nfds,
xnticks_t  timeout,
xntmode_t  timeout_mode 
)

Check the state of a number of file descriptors, wait for a state change if no descriptor is ready.

Parameters
selectorstructure to check for pending events
out_fdsThe set of descriptors with pending events if a strictly positive number is returned, or the set of descriptors not yet bound if -ECHRNG is returned;
in_fdsthe set of descriptors which events should be checked
nfdsthe highest-numbered descriptor in any of the in_fds sets, plus 1;
timeoutthe timeout, whose meaning depends on timeout_mode, note that xnselect() pass timeout and timeout_mode unchanged to xnsynch_sleep_on, so passing a relative value different from XN_INFINITE as a timeout with timeout_mode set to XN_RELATIVE, will cause a longer sleep than expected if the sleep is interrupted.
timeout_modethe mode of timeout.
Return values
-EINVALif nfds is negative;
-ECHRNGif some of the descriptors passed in in_fds have not yet been registered with xnselect_bind(), out_fds contains the set of such descriptors;
-EINTRif xnselect was interrupted while waiting;
0in case of timeout.
thenumber of file descriptors having received an event.
Tags
primary-only, might-switch

◆ xnselect_bind()

int xnselect_bind ( struct xnselect select_block,
struct xnselect_binding *  binding,
struct xnselector *  selector,
unsigned  type,
unsigned  index,
unsigned  state 
)

Bind a file descriptor (represented by its xnselect structure) to a selector block.

Parameters
select_blockpointer to the struct xnselect to be bound;
bindingpointer to a newly allocated (using xnmalloc) struct xnselect_binding;
selectorpointer to the selector structure;
typetype of events (XNSELECT_READ, XNSELECT_WRITE, or XNSELECT_EXCEPT);
indexindex of the file descriptor (represented by select_block) in the bit fields used by the selector structure;
statecurrent state of the file descriptor.

select_block must have been initialized with xnselect_init(), the xnselector structure must have been initialized with xnselector_init(), binding may be uninitialized.

This service must be called with nklock locked, irqs off. For this reason, the binding parameter must have been allocated by the caller outside the locking section.

Return values
-EINVALif type or index is invalid;
0otherwise.
Tags
task-unrestricted, might-switch, atomic-entry

◆ xnselect_destroy()

void xnselect_destroy ( struct xnselect select_block)

Destroy the xnselect structure associated with a file descriptor.

Any binding with a xnselector block is destroyed.

Parameters
select_blockpointer to the xnselect structure associated with a file descriptor
Tags
task-unrestricted, might-switch

Referenced by rtdm_event_destroy(), and rtdm_sem_destroy().

◆ xnselect_init()

void xnselect_init ( struct xnselect select_block)

Initialize a struct xnselect structure.

This service must be called to initialize a struct xnselect structure before it is bound to a selector by the means of xnselect_bind().

Parameters
select_blockpointer to the xnselect structure to be initialized
Tags
task-unrestricted

◆ xnselect_signal()

static int xnselect_signal ( struct xnselect select_block,
unsigned int  state 
)
inlinestatic

Signal a file descriptor state change.

Parameters
select_blockpointer to an xnselect structure representing the file descriptor whose state changed;
statenew value of the state.
Return values
1if rescheduling is needed;
0otherwise.

◆ xnselector_destroy()

void xnselector_destroy ( struct xnselector *  selector)

Destroy a selector block.

All bindings with file descriptor are destroyed.

Parameters
selectorthe selector block to be destroyed
Tags
task-unrestricted

◆ xnselector_init()

int xnselector_init ( struct xnselector *  selector)

Initialize a selector structure.

Parameters
selectorThe selector structure to be initialized.
Return values
0
Tags
task-unrestricted

References xnsynch_init().