From 50e1484af0d443b46aa04fd4a8096b157dc160aa Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 16 Jan 2017 19:35:51 -0800 Subject: Recv/Send event plumbing implemented (msgqueue and up). This change provides for a private callback in the message queues, which can be used to notify the socket, and which than arranges for the appropriate event thread to run. Upper layer hooks to access this still need to be written. --- src/core/event.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/core/event.c') diff --git a/src/core/event.c b/src/core/event.c index 3f7d1143..1b264632 100644 --- a/src/core/event.c +++ b/src/core/event.c @@ -13,7 +13,7 @@ #include int -nni_event_init(nni_event *event, int type, nni_sock *sock) +nni_ev_init(nni_event *event, int type, nni_sock *sock) { int rv; @@ -29,15 +29,26 @@ nni_event_init(nni_event *event, int type, nni_sock *sock) void -nni_event_fini(nni_event *event) +nni_ev_fini(nni_event *event) { nni_cv_fini(&event->e_cv); } void -nni_event_submit(nni_sock *sock, nni_event *event) +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; + } + // Call with socket mutex owned! if (event->e_pending == 0) { event->e_pending = 1; @@ -49,7 +60,7 @@ nni_event_submit(nni_sock *sock, nni_event *event) void -nni_event_wait(nni_sock *sock, nni_event *event) +nni_ev_wait(nni_event *event) { // Call with socket mutex owned! // Note that the socket mutex is dropped during the call. @@ -60,7 +71,7 @@ nni_event_wait(nni_sock *sock, nni_event *event) void -nni_event_notifier(void *arg) +nni_notifier(void *arg) { nni_sock *sock = arg; nni_event *event; -- cgit v1.2.3-70-g09d2