diff options
| author | Garrett D'Amore <garrett@damore.org> | 2020-02-06 01:14:13 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2020-02-06 01:22:21 -0800 |
| commit | 2dc8214259155d264a50ca56aa88782b304d3afd (patch) | |
| tree | 80cb9aa07315fe8929f18fbdba6773fe95f5b543 | |
| parent | 105bb7216101514a4563252775bcbf1650abadc9 (diff) | |
| download | nng-2dc8214259155d264a50ca56aa88782b304d3afd.tar.gz nng-2dc8214259155d264a50ca56aa88782b304d3afd.tar.bz2 nng-2dc8214259155d264a50ca56aa88782b304d3afd.zip | |
fixes #814 mq_get_error should go
| -rw-r--r-- | src/core/msgqueue.c | 59 | ||||
| -rw-r--r-- | src/core/msgqueue.h | 13 |
2 files changed, 2 insertions, 70 deletions
diff --git a/src/core/msgqueue.c b/src/core/msgqueue.c index 697ca503..2d767d45 100644 --- a/src/core/msgqueue.c +++ b/src/core/msgqueue.c @@ -1,5 +1,5 @@ // -// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -22,7 +22,6 @@ struct nni_msgq { int mq_len; int mq_get; int mq_put; - int mq_geterr; bool mq_closed; nni_msg **mq_msgs; @@ -67,7 +66,6 @@ nni_msgq_init(nni_msgq **mqp, unsigned cap) mq->mq_get = 0; mq->mq_put = 0; mq->mq_closed = 0; - mq->mq_geterr = 0; *mqp = mq; return (0); @@ -102,43 +100,6 @@ nni_msgq_fini(nni_msgq *mq) NNI_FREE_STRUCT(mq); } -void -nni_msgq_set_get_error(nni_msgq *mq, int error) -{ - // Let all pending blockers know we are closing the queue. - nni_mtx_lock(&mq->mq_lock); - if (mq->mq_closed) { - // If we were closed, then this error trumps all others. - error = NNG_ECLOSED; - } - if (error != 0) { - nni_aio *aio; - while ((aio = nni_list_first(&mq->mq_aio_getq)) != NULL) { - nni_aio_list_remove(aio); - nni_aio_finish_error(aio, error); - } - } - mq->mq_geterr = error; - nni_msgq_run_notify(mq); - nni_mtx_unlock(&mq->mq_lock); -} - -void -nni_msgq_flush(nni_msgq *mq) -{ - nni_mtx_lock(&mq->mq_lock); - while (mq->mq_len > 0) { - nni_msg *msg = mq->mq_msgs[mq->mq_get++]; - if (mq->mq_get >= mq->mq_alloc) { - mq->mq_get = 0; - } - mq->mq_len--; - nni_msg_free(msg); - } - nni_msgq_run_notify(mq); - nni_mtx_unlock(&mq->mq_lock); -} - static void nni_msgq_run_putq(nni_msgq *mq) { @@ -287,11 +248,6 @@ nni_msgq_aio_get(nni_msgq *mq, nni_aio *aio) return; } nni_mtx_lock(&mq->mq_lock); - if (mq->mq_geterr) { - nni_mtx_unlock(&mq->mq_lock); - nni_aio_finish_error(aio, mq->mq_geterr); - return; - } rv = nni_aio_schedule(aio, nni_msgq_cancel, mq); if ((rv != 0) && (mq->mq_len == 0) && (nni_list_empty(&mq->mq_aio_putq))) { @@ -353,8 +309,6 @@ nni_msgq_close(nni_msgq *mq) nni_mtx_lock(&mq->mq_lock); mq->mq_closed = true; - mq->mq_geterr = NNG_ECLOSED; - // Free the messages orphaned in the queue. while (mq->mq_len > 0) { nni_msg *msg = mq->mq_msgs[mq->mq_get++]; @@ -376,17 +330,6 @@ nni_msgq_close(nni_msgq *mq) } int -nni_msgq_len(nni_msgq *mq) -{ - int rv; - - nni_mtx_lock(&mq->mq_lock); - rv = mq->mq_len; - nni_mtx_unlock(&mq->mq_lock); - return (rv); -} - -int nni_msgq_cap(nni_msgq *mq) { int rv; diff --git a/src/core/msgqueue.h b/src/core/msgqueue.h index 2c43e540..d264ee3f 100644 --- a/src/core/msgqueue.h +++ b/src/core/msgqueue.h @@ -1,5 +1,5 @@ // -// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -33,9 +33,6 @@ extern int nni_msgq_init(nni_msgq **, unsigned); // messages that may be in the queue. extern void nni_msgq_fini(nni_msgq *); -// nni_msgq_flush discards any messages that are sitting in the queue. -// It does not wake any writers that might be waiting. -extern void nni_msgq_flush(nni_msgq *); extern void nni_msgq_aio_put(nni_msgq *, nni_aio *); extern void nni_msgq_aio_get(nni_msgq *, nni_aio *); @@ -44,11 +41,6 @@ extern void nni_msgq_aio_get(nni_msgq *, nni_aio *); // the message queue. extern int nni_msgq_tryput(nni_msgq *, nni_msg *); -// nni_msgq_set_get_error sets an error condition on the get side of the -// message queue, and for that side behaves like nni_msgq_set_error. -// Readers (nni_msgq_put*) are unaffected. -extern void nni_msgq_set_get_error(nni_msgq *, int); - // nni_msgq_close closes the queue. After this all operates on the // message queue will return NNG_ECLOSED. Messages inside the queue // are freed. Unlike closing a go channel, this operation is idempotent. @@ -66,9 +58,6 @@ extern int nni_msgq_resize(nni_msgq *, int); // for the message queue to contain up to 2 more messages than the capacity. extern int nni_msgq_cap(nni_msgq *mq); -// nni_msgq_len returns the number of messages currently in the queue. -extern int nni_msgq_len(nni_msgq *mq); - extern int nni_msgq_get_recvable(nni_msgq *mq, nni_pollable **); extern int nni_msgq_get_sendable(nni_msgq *mq, nni_pollable **); |
