mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
cd62b74b1c
Since they're short, we use a simple array. This can be replaced later. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
31 lines
533 B
C
31 lines
533 B
C
#include <lightningd/msg_queue.h>
|
|
|
|
void msg_queue_init(struct msg_queue *q, const tal_t *ctx)
|
|
{
|
|
q->q = tal_arr(ctx, const u8 *, 0);
|
|
}
|
|
|
|
void msg_enqueue(struct msg_queue *q, const u8 *add)
|
|
{
|
|
size_t n = tal_count(q->q);
|
|
tal_resize(&q->q, n+1);
|
|
q->q[n] = add;
|
|
|
|
/* In case someone is waiting */
|
|
io_wake(q);
|
|
}
|
|
|
|
const u8 *msg_dequeue(struct msg_queue *q)
|
|
{
|
|
size_t n = tal_count(q->q);
|
|
const u8 *msg;
|
|
|
|
if (!n)
|
|
return NULL;
|
|
|
|
msg = q->q[0];
|
|
memmove(q->q, q->q + 1, sizeof(*q->q) * (n-1));
|
|
tal_resize(&q->q, n-1);
|
|
return msg;
|
|
}
|