Waiting on several message queues at once.
More...
Waiting on several message queues at once.
pbl_poll_group_wait() returns a member queue that has a message without dequeuing it; the caller receives it with pbl_msgq_get(). Members are scanned from the one after the last returned, so a busy queue cannot starve the others. Members may also be read directly, outside the group. Queues are added before the first wait and stay members for good; only one thread may wait on a group.
static void prv_loop(void *arg) {
for (;;) {
if (q == NULL) {
prv_handle_timeout();
continue;
}
struct event e;
prv_handle(q, &e);
}
}
}
Fixed-size message ring.
Definition msgq.h:46
int pbl_msgq_get(struct pbl_msgq *q, void *msg, pbl_timeout_t timeout)
Receive the oldest message.
#define PBL_MSGQ_DEFINE(name, size, max)
Define a queue with its own storage, usable without pbl_msgq_init().
Definition msgq.h:91
#define PBL_POLL_GROUP_DEFINE(name)
Define an empty group, usable without pbl_poll_group_init().
Definition poll.h:62
struct pbl_msgq * pbl_poll_group_wait(struct pbl_poll_group *g, pbl_timeout_t timeout)
Wait until a member queue has a message.
void pbl_poll_group_add(struct pbl_poll_group *g, struct pbl_msgq *q)
Add a queue to a group.
#define PBL_NO_WAIT
Do not wait: fail with -EBUSY if the call would block.
Definition types.h:48
#define PBL_SEC(s)
Timeout in seconds.
Definition types.h:68
◆ pbl_poll_group
Set of message queues waited on together.
| Data Fields |
|
struct pbl_poll_group_backend |
backend |
Backend state. |
|
uint32_t |
capacity |
Sum of the capacities of all members, in messages. |
|
struct pbl_msgq * |
members |
First member queue, in the order they were added. |
◆ PBL_POLL_GROUP_DEFINE
◆ PBL_POLL_GROUP_INITIALIZER
| #define PBL_POLL_GROUP_INITIALIZER {.members = NULL, .capacity = 0} |
Static initializer for an empty group.
◆ pbl_poll_group_add()
Add a queue to a group.
- Parameters
-
| g | Group. |
| q | Queue; must be empty and not already in a group. |
◆ pbl_poll_group_init()
Initialize a group in dynamically allocated memory.
- Parameters
-
◆ pbl_poll_group_is_empty()
Check whether every member queue is empty.
- Parameters
-
- Returns
- true if no member has a message.
◆ pbl_poll_group_wait()
Wait until a member queue has a message.
Not callable from ISRs. The group must have at least one member.
- Parameters
-
| g | Group. |
| timeout | How long to wait. |
- Returns
- A member with a pending message, or NULL on timeout or if the thread was suspended while waiting.