Skip to content

Commit

Permalink
* NEW [nng] Expose lmq to public.
Browse files Browse the repository at this point in the history
Signed-off-by: wanghaemq <[email protected]>
  • Loading branch information
wanghaEMQ committed Jan 8, 2025
1 parent 3c125d0 commit 217827e
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/nng/nng.h
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,18 @@ NNG_DECL void nng_cv_wake(nng_cv *);
// reduce the thundering herd problem, but care must be taken to ensure
// that no waiter starves forever.
NNG_DECL void nng_cv_wake1(nng_cv *);

typedef struct nng_lmq nng_lmq;

NNG_DECL int nng_lmq_alloc(nng_lmq **qp, size_t sz);
NNG_DECL void nng_lmq_free(nng_lmq *q);
NNG_DECL size_t nng_lmq_len(nng_lmq *q);
NNG_DECL size_t nng_lmq_cap(nng_lmq *q);
NNG_DECL int nng_lmq_put(nng_lmq *q, nng_msg *m);
NNG_DECL int nng_lmq_get(nng_lmq *q, nng_msg **mp);
NNG_DECL bool nng_lmq_full(nng_lmq *q);
NNG_DECL bool nng_lmq_empty(nng_lmq *q);

// Logging support.

// Log levels. These correspond to RFC 5424 (syslog) levels.
Expand Down
62 changes: 62 additions & 0 deletions src/nng.c
Original file line number Diff line number Diff line change
Expand Up @@ -2194,6 +2194,68 @@ nng_cv_wake1(nng_cv *cv)
nni_cv_wake1(&cv->c);
}

struct nng_lmq {
nni_lmq q;
};

int
nng_lmq_alloc(nng_lmq **qp, size_t sz)
{
nng_lmq *q;

if ((q = NNI_ALLOC_STRUCT(q)) == NULL) {
return (NNG_ENOMEM);
}
nni_lmq_init(&q->q, sz);
*qp = q;
return (0);
}

void
nng_lmq_free(nng_lmq *q)
{
if (q != NULL) {
nni_lmq_fini(&q->q);
NNI_FREE_STRUCT(q);
}
}

size_t
nng_lmq_len(nng_lmq *q)
{
return nni_lmq_len(&q->q);
}

size_t
nng_lmq_cap(nng_lmq *q)
{
return nni_lmq_cap(&q->q);
}

int
nng_lmq_put(nng_lmq *q, nng_msg *m)
{
return nni_lmq_put(&q->q, m);
}

int
nng_lmq_get(nng_lmq *q, nng_msg **mp)
{
return nni_lmq_get(&q->q, mp);
}

bool
nng_lmq_full(nng_lmq *q)
{
return nni_lmq_full(&q->q);
}

bool
nng_lmq_empty(nng_lmq *q)
{
return nni_lmq_empty(&q->q);
}

uint32_t
nng_random(void)
{
Expand Down

0 comments on commit 217827e

Please sign in to comment.