blob: c44ca24c6b567c66ac4d1686df87bd2a367c75de (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
//
// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
// file was obtained (LICENSE.txt). A copy of the license may also be
// found online at https://opensource.org/licenses/MIT.
//
#ifndef CORE_LMQ_H
#define CORE_LMQ_H
#include "core/defs.h"
// nni_lmq is a very lightweight message queue. Defining it this way allows
// us to share some common code. Locking must be supplied by the caller.
// For performance reasons, this is allocated inline.
typedef struct nni_lmq {
size_t lmq_cap;
size_t lmq_alloc; // alloc is cap, rounded up to power of 2
size_t lmq_mask;
size_t lmq_len;
size_t lmq_get;
size_t lmq_put;
nng_msg **lmq_msgs;
nng_msg *lmq_buf[2]; // default minimal buffer
} nni_lmq;
extern void nni_lmq_init(nni_lmq *, size_t);
extern void nni_lmq_fini(nni_lmq *);
extern void nni_lmq_flush(nni_lmq *);
extern size_t nni_lmq_len(nni_lmq *);
extern size_t nni_lmq_cap(nni_lmq *);
extern int nni_lmq_put(nni_lmq *lmq, nng_msg *msg);
extern int nni_lmq_get(nni_lmq *lmq, nng_msg **mp);
extern int nni_lmq_resize(nni_lmq *, size_t);
extern bool nni_lmq_full(nni_lmq *);
extern bool nni_lmq_empty(nni_lmq *);
#endif // CORE_LMQ_H
|