Message queue
Passing messages through a queue
An EVL message queue carries messages of a fixed maximum size, from any number of senders to any number of receivers, in the same process or across processes. Its semantics are close to the POSIX message queues:
-
each message has a priority, from 0 to
EVL_MQ_PRIO_MAX - 1(63). A receiver gets the oldest message of the highest priority first. -
the queue holds up to a maximum number of messages set at creation time. A sender waits for room when the queue is full, a receiver waits for a message when it is empty.
-
each sent message is copied into the queue, then copied to the buffer of the receiver.
The messages are stored in a memory area which every process using the queue maps, so that sending and receiving involve no system call unless the caller has to wait, or has to wake up a waiter. A message queue is a sibling of the cross-buffer, which carries a byte stream instead of separate messages.
A thread waits on a queue from the out-of-band stage, unless it
undergoes the SCHED_WEAK policy, in which case
it waits in-band. A thread which is not attached to the core cannot
wait: it may only call evl_trysend_mq() and evl_tryreceive_mq(),
or use a queue descriptor in non-blocking mode (see
EVL_CLONE_NONBLOCK). Otherwise, it gets -EPERM, even if the call
would not have to wait.
The file descriptor of a queue can be polled: POLLIN tells that a message is
waiting, POLLOUT that the queue has room for a message.
Message queue services
evl_create_mq() | Create a message queue, setting its clock, size and visibility. | in-band |
evl_new_mq() | Create a private message queue timed on the monotonic clock. | in-band |
EVL_MQ_INITIALIZER | Initialize a message queue statically, created on first use. | |
DEFINE_EVL_MQ | Define a private message queue statically, created on first use. | |
evl_open_mq() | Open an existing public message queue. | in-band |
evl_close_mq() | Close a message queue. | in-band |
evl_unlink_mq() | Remove the device file of a public message queue. | in-band |
evl_send_mq() | Send a message, waiting for room in the queue. | conforming |
evl_timedsend_mq() | Send a message, waiting for room in the queue until a time limit. | conforming |
evl_trysend_mq() | Send a message if the queue has room, without waiting. | no stage switch |
evl_receive_mq() | Receive the message of highest priority, waiting for one. | conforming |
evl_timedreceive_mq() | Receive the message of highest priority, waiting until a time limit. | conforming |
evl_tryreceive_mq() | Receive a message if one is queued, without waiting. | no stage switch |
evl_peek_mq() | Read the number of messages in a queue. | no stage switch |
int evl_create_mq(struct evl_mq *mq, int clockfd, size_t maxmsg, size_t msgsize, int flags, const char *fmt, ...)
#include <evl/mq.h>
in-band
non-EVL threads: yes
This call creates a message queue, returning a file descriptor representing the new object upon success. This is the generic call form; for creating a queue with common pre-defined settings, see evl_new_mq().
mqAn in-memory queue descriptor is constructed by evl_create_mq(), which contains ancillary information
other calls will need. mq is a pointer to such descriptor of type
struct evl_mq.
clockfdThe EVL clock which measures the timeouts of evl_timedsend_mq() and evl_timedreceive_mq(). Built-in EVL clocks are accepted here.
maxmsgThe maximum number of messages the queue can hold, from 1 to
EVL_MQ_MAXMSG_MAX (65536).
msgsizeThe maximum size of a message in bytes, from 1 to EVL_MQ_MSGSIZE_MAX
(16 MiB). The memory needed for maxmsg messages of this size must
not exceed 1 GiB.
flagsA set of creation flags for the new element, defining its visibility:
-
EVL_CLONE_PUBLICdenotes a public element which is represented by a device file in the /dev/evl/depot directory, which makes it visible to other processes for sharing. -
EVL_CLONE_PRIVATEdenotes an element which is private to the calling process. No device file appears for it in the /dev/evl file hierarchy. -
EVL_CLONE_PERSISTENTkeeps a public queue alive when no file descriptor refers to it any more, until evl_unlink_mq() removes it. This flag is valid only withEVL_CLONE_PUBLIC. -
EVL_CLONE_NONBLOCKsets the file descriptor of the new queue in non-blocking I/O mode (O_NONBLOCK): a call which would have to wait fails with-EAGAINinstead. By default,O_NONBLOCKis cleared for the file descriptor.
fmtA printf-like format string to generate the queue name. See this description of the naming convention.
...The optional variable argument list completing the format.
evl_create_mq() returns the file descriptor of the new queue on success. Otherwise, a negated error code is returned:
| Error | Meaning |
|---|---|
-EEXIST |
The generated name is conflicting with an existing queue name. |
-EINVAL |
Either clockfd does not refer to a valid EVL clock, maxmsg or msgsize is out of range, the queue would need more than 1 GiB, flags is wrong, or the generated name is badly formed. |
-ENAMETOOLONG |
The overall length of the device element’s file path including the generated name exceeds PATH_MAX. |
-EMFILE |
The per-process limit on the number of open file descriptors has been reached. |
-ENFILE |
The system-wide limit on the total number of open files has been reached. |
-ENOMEM |
No memory available. |
-ENXIO |
The EVL library is not initialized for the current process. Such initialization happens implicitly when evl_attach_self() is called by any thread of your process, or by explicitly calling evl_init(). |
int evl_new_mq(struct evl_mq *mq, size_t maxmsg, size_t msgsize, const char *fmt, ...)
#include <evl/mq.h>
in-band
non-EVL threads: yes
This call is a shorthand for creating a private queue, timed on the built-in EVL monotonic clock. It is identical to calling:
Info
Note that if the generated name starts with a
slash (’/’) character, EVL_CLONE_PRIVATE would be automatically turned
into EVL_CLONE_PUBLIC internally.
EVL_MQ_INITIALIZER((const char *) name, (int) clockfd, (size_t) maxmsg, (size_t) msgsize, (int) flags)
#include <evl/mq.h>
The static initializer you can use with message queues. All arguments to this macro refer to their counterpart in the call to evl_create_mq(). The queue is created on first use, which may switch the caller to the in-band stage once.
Define a variable of type struct evl_mq called name, statically
initialized as a private queue timed on the built-in monotonic clock.
The variable name is also the name of the queue. Like with
EVL_MQ_INITIALIZER, the queue
is created on first use.
int evl_open_mq(struct evl_mq *mq, const char *fmt, ...)
#include <evl/mq.h>
in-band
non-EVL threads: yes
You can open an existing public queue, possibly from a different process, by calling evl_open_mq().
mqAn in-memory queue descriptor is constructed by evl_open_mq(), which contains ancillary information other calls will need. The information is retrieved from the existing queue which was opened.
fmtA printf-like format string to generate the name of the queue to open. This name must exist in the EVL device file hierarchy at /dev/evl/depot. See this description of the naming convention.
...The optional variable argument list completing the format.
evl_open_mq() returns the file descriptor referring to the opened queue on success. Otherwise, a negated error code is returned:
| Error | Meaning |
|---|---|
-ENOENT |
No queue of this name exists. |
-EINVAL |
The queue layout is not the one this library expects. |
-EMFILE |
The per-process limit on the number of open file descriptors has been reached. |
-ENFILE |
The system-wide limit on the total number of open files has been reached. |
-ENOMEM |
No memory available. |
-ENXIO |
The EVL library is not initialized for the current process. |
Close a queue, unmapping its memory area from the calling process. A private queue, or a public queue which is not persistent, is deleted when the last file descriptor referring to it is closed. Closing a statically initialized queue which was never used has no effect.
mqThe in-memory queue descriptor to close.
evl_close_mq() returns zero on success. Otherwise, a negated error code is returned:
| Error | Meaning |
|---|---|
-EINVAL |
mq does not represent a valid in-memory queue descriptor. |
Remove the device file of a public queue from the /dev/evl/depot directory, so that no process can open it any more. A persistent queue is no longer kept alive: it is deleted when the last file descriptor referring to it is closed. The processes which have the queue open can keep using it until then.
fmtA printf-like format string to generate the name of the queue to remove.
...The optional variable argument list completing the format.
evl_unlink_mq() returns zero on success. Otherwise, a negated error code is returned:
| Error | Meaning |
|---|---|
-ENOENT |
No queue of this name exists, or it was already unlinked. |
-ENOMEM |
No memory available. |
int evl_send_mq(struct evl_mq *mq, const void *buf, size_t len, unsigned int prio)
#include <evl/mq.h>
conforming
non-EVL threads: no
Send a message, waiting for room in the queue if it is full. A thread waiting to receive from the queue is woken up.
mqThe in-memory queue descriptor constructed by either evl_create_mq() or evl_open_mq(), or statically built with EVL_MQ_INITIALIZER. In the latter case, the queue is created before the message is sent, which may switch the caller to the in-band stage.
bufThe message to send.
lenThe size of the message in bytes, which must not exceed the maximum message size of the queue.
prioThe priority of the message, from 0 to EVL_MQ_PRIO_MAX - 1.
evl_send_mq() returns zero on success. Otherwise, a negated error code is returned:
| Error | Meaning |
|---|---|
-EINVAL |
mq does not represent a valid in-memory queue descriptor, or prio is out of range. |
-EMSGSIZE |
len exceeds the maximum message size of the queue. |
-EAGAIN |
The queue is full and its descriptor is in non-blocking mode. |
-EPERM |
The caller is not attached to the core, and the descriptor of the queue is in blocking mode. |
-EINTR |
The wait was interrupted by an in-band signal, or forcibly unblocked by the EVL core. |
If mq was statically initialized but not used yet, any error status returned by evl_create_mq() may be passed back to the caller in case the implicit creation fails.
int evl_timedsend_mq(struct evl_mq *mq, const void *buf, size_t len, unsigned int prio, const struct timespec *timeout)
#include <evl/mq.h>
conforming
non-EVL threads: no
A variant of evl_send_mq() which gives up waiting for room when a time limit is reached.
timeoutThe date at which the wait ends, measured by the clock of the queue. A NULL timeout means no time limit.
The other arguments are the same as for evl_send_mq(). The possible return values include any status from evl_send_mq(), plus:
| Error | Meaning |
|---|---|
-ETIMEDOUT |
The time limit was reached before the queue had room. |
int evl_trysend_mq(struct evl_mq *mq, const void *buf, size_t len, unsigned int prio)
#include <evl/mq.h>
no stage switch
non-EVL threads: yes
A variant of evl_send_mq() which
never waits: if the queue is full, it fails with -EAGAIN. Any thread
may call it, including one which is not attached to the core.
ssize_t evl_receive_mq(struct evl_mq *mq, void *buf, size_t len, unsigned int *r_prio)
#include <evl/mq.h>
conforming
non-EVL threads: no
Receive the oldest message of the highest priority, waiting for a message if the queue is empty. A thread waiting to send to the queue is woken up.
mqThe in-memory queue descriptor, as for evl_send_mq().
bufThe buffer which receives the message.
lenThe size of buf in bytes, which must be at least the maximum message size of the queue.
r_prioIf not NULL, the address of a variable which receives the priority of the message.
evl_receive_mq() returns the size of the message in bytes on success. Otherwise, a negated error code is returned:
| Error | Meaning |
|---|---|
-EINVAL |
mq does not represent a valid in-memory queue descriptor. |
-EMSGSIZE |
len is smaller than the maximum message size of the queue. |
-EAGAIN |
The queue is empty and its descriptor is in non-blocking mode. |
-EPERM |
The caller is not attached to the core, and the descriptor of the queue is in blocking mode. |
-EINTR |
The wait was interrupted by an in-band signal, or forcibly unblocked by the EVL core. |
ssize_t evl_timedreceive_mq(struct evl_mq *mq, void *buf, size_t len, unsigned int *r_prio, const struct timespec *timeout)
#include <evl/mq.h>
conforming
non-EVL threads: no
A variant of evl_receive_mq() which gives up waiting for a message when a time limit is reached.
timeoutThe date at which the wait ends, measured by the clock of the queue. A NULL timeout means no time limit.
The other arguments are the same as for evl_receive_mq(). The possible return values include any status from evl_receive_mq(), plus:
| Error | Meaning |
|---|---|
-ETIMEDOUT |
The time limit was reached before a message arrived. |
ssize_t evl_tryreceive_mq(struct evl_mq *mq, void *buf, size_t len, unsigned int *r_prio)
#include <evl/mq.h>
no stage switch
non-EVL threads: yes
A variant of evl_receive_mq()
which never waits: if the queue is empty, it fails with -EAGAIN. Any
thread may call it, including one which is not attached to the core.
int evl_peek_mq(struct evl_mq *mq, int *r_count)
#include <evl/mq.h>
no stage switch
non-EVL threads: yes
Read the number of messages waiting in a queue. The value may be stale by the time the caller looks at it, if other threads send or receive concurrently.
mqThe in-memory queue descriptor, as for evl_send_mq().
r_countThe address of a variable which receives the number of messages.
evl_peek_mq() returns zero on
success, or -EINVAL if mq does not represent a valid in-memory
queue descriptor.
Last modified: Wed, 25 Nov 2026 16:53:53 +0100