From 4250fc119057eb6a6b534e9c0758488cc5fb034e Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Tue, 24 Oct 2017 15:26:14 -0700 Subject: fixes #132 Implement saner notification for file descriptors This eliminates the "quasi-functional" notify API altogether. The aio framework will be coming soon to replace it. As a bonus, apps (legacy apps) that use the notification FDs will see improved performance, since we don't have to context switch to give them a notification. --- src/core/msgqueue.h | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'src/core/msgqueue.h') diff --git a/src/core/msgqueue.h b/src/core/msgqueue.h index bbac505d..ececf372 100644 --- a/src/core/msgqueue.h +++ b/src/core/msgqueue.h @@ -38,8 +38,6 @@ extern void nni_msgq_fini(nni_msgq *); extern void nni_msgq_aio_put(nni_msgq *, nni_aio *); extern void nni_msgq_aio_get(nni_msgq *, nni_aio *); -extern void nni_msgq_aio_notify_get(nni_msgq *, nni_aio *); -extern void nni_msgq_aio_notify_put(nni_msgq *, nni_aio *); // nni_msgq_tryput performs a non-blocking attempt to put a message on // the message queue. It is the same as calling nng_msgq_put_until with @@ -83,6 +81,28 @@ typedef nni_msg *(*nni_msgq_filter)(void *, nni_msg *); // discarded instead, and any get waiters remain waiting. extern void nni_msgq_set_filter(nni_msgq *, nni_msgq_filter, void *); +// nni_msgq_cb_flags is an enumeration of flag bits used with nni_msgq_cb. +enum nni_msgq_cb_flags { + nni_msgq_f_full = 1, + nni_msgq_f_empty = 2, + nni_msgq_f_can_get = 4, + nni_msgq_f_can_put = 8, + nni_msgq_f_closed = 16, +}; + +// nni_msgq_cb is a callback function used by sockets to monitor +// the status of the queue. It is called with the lock held for +// performance reasons so consumers must not re-enter the queue. +// The purpose is to enable file descriptor notifications on the socket, +// which don't need to reenter the msgq. The integer is a mask of +// flags that are true for the given message queue. +typedef void (*nni_msgq_cb)(void *, int); + +// nni_msgq_set_cb sets the callback and argument for the callback +// which will be called on state changes in the message queue. Only +// one callback can be registered on a message queue at a time. +extern void nni_msgq_set_cb(nni_msgq *, nni_msgq_cb, void *); + // 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. -- cgit v1.2.3-70-g09d2