aboutsummaryrefslogtreecommitdiff
path: root/src/core/event.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-03-11 22:38:21 -0800
committerGarrett D'Amore <garrett@damore.org>2017-03-11 22:38:21 -0800
commit3d4be5126f91978b7d7349de79334ecfc8fc2afe (patch)
treec8cfadbb1096e99cad21bddbb9fe9ff7b5dd175a /src/core/event.c
parent3d90bae8eda62fecdf367932fca591b965838e20 (diff)
downloadnng-3d4be5126f91978b7d7349de79334ecfc8fc2afe.tar.gz
nng-3d4be5126f91978b7d7349de79334ecfc8fc2afe.tar.bz2
nng-3d4be5126f91978b7d7349de79334ecfc8fc2afe.zip
Notification working - separate thread now.
Diffstat (limited to 'src/core/event.c')
-rw-r--r--src/core/event.c111
1 files changed, 1 insertions, 110 deletions
diff --git a/src/core/event.c b/src/core/event.c
index 98156a92..b0e02b16 100644
--- a/src/core/event.c
+++ b/src/core/event.c
@@ -18,10 +18,6 @@ nni_ev_init(nni_event *event, int type, nni_sock *sock)
int rv;
memset(event, 0, sizeof (*event));
- if ((rv = nni_cv_init(&event->e_cv, &sock->s_mx)) != 0) {
- return (rv);
- }
- NNI_LIST_NODE_INIT(&event->e_node);
event->e_type = type;
event->e_sock = sock;
return (0);
@@ -31,110 +27,5 @@ nni_ev_init(nni_event *event, int type, nni_sock *sock)
void
nni_ev_fini(nni_event *event)
{
- nni_cv_fini(&event->e_cv);
-}
-
-
-void
-nni_ev_submit(nni_event *event)
-{
- nni_sock *sock = event->e_sock;
-
- // If nobody is listening, don't bother submitting anything.
- // This reduces pressure on the socket locks & condvars, in the
- // typical case.
- if (nni_list_first(&sock->s_notify) == NULL) {
- event->e_pending = 0;
- event->e_done = 1;
- return;
- }
-
- // XXX: taskq_dispatch the event processing.
- // This probably should bump a reference count on the socket
- // first.
- // XXX: One question of note... the aio structures we use elsewhere
- // would be better than this. So instead of the handler doing two
- // context switches we can just do one.
-
- // Call with socket mutex owned!
- if (event->e_pending == 0) {
- event->e_pending = 1;
- event->e_done = 0;
- nni_list_append(&sock->s_events, event);
- nni_cv_wake(&sock->s_notify_cv);
- }
-}
-
-
-void
-nni_notifier(void *arg)
-{
- nni_sock *sock = arg;
- nni_event *event;
- nni_notify *notify;
-
- nni_mtx_lock(&sock->s_mx);
- for (;;) {
- if (sock->s_closing) {
- break;
- }
-
- if ((event = nni_list_first(&sock->s_events)) != NULL) {
- event->e_pending = 0;
- nni_list_remove(&sock->s_events, event);
- nni_mtx_unlock(&sock->s_mx);
-
- // Lock the notify list, it must not change.
- nni_mtx_lock(&sock->s_notify_mx);
- NNI_LIST_FOREACH (&sock->s_notify, notify) {
- if ((notify->n_mask & event->e_type) == 0) {
- // No interest.
- continue;
- }
- notify->n_func(event, notify->n_arg);
- }
- nni_mtx_unlock(&sock->s_notify_mx);
-
- nni_mtx_lock(&sock->s_mx);
- // Let the event submitter know we are done, unless
- // they have resubmitted. Submitters can wait on this
- // lock.
- event->e_done = 1;
- nni_cv_wake(&event->e_cv);
- continue;
- }
-
- nni_cv_wait(&sock->s_notify_cv);
- }
- nni_mtx_unlock(&sock->s_mx);
-}
-
-
-nni_notify *
-nni_add_notify(nni_sock *sock, int mask, nng_notify_func fn, void *arg)
-{
- nni_notify *notify;
-
- if ((notify = NNI_ALLOC_STRUCT(notify)) == NULL) {
- return (NULL);
- }
- notify->n_func = fn;
- notify->n_arg = arg;
- notify->n_mask = mask;
- NNI_LIST_NODE_INIT(&notify->n_node);
-
- nni_mtx_lock(&sock->s_notify_mx);
- nni_list_append(&sock->s_notify, notify);
- nni_mtx_unlock(&sock->s_notify_mx);
- return (notify);
-}
-
-
-void
-nni_rem_notify(nni_sock *sock, nni_notify *notify)
-{
- nni_mtx_lock(&sock->s_notify_mx);
- nni_list_remove(&sock->s_notify, notify);
- nni_mtx_unlock(&sock->s_notify_mx);
- NNI_FREE_STRUCT(notify);
+ NNI_ARG_UNUSED(event);
}