aboutsummaryrefslogtreecommitdiff
path: root/src/core/event.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-01-16 19:35:51 -0800
committerGarrett D'Amore <garrett@damore.org>2017-01-16 19:35:51 -0800
commit50e1484af0d443b46aa04fd4a8096b157dc160aa (patch)
treeab517217c82e785b0c851c986ee44dfc4a4a65fe /src/core/event.c
parentac8415c24ffea645105c3859e814843e81c97f8a (diff)
downloadnng-50e1484af0d443b46aa04fd4a8096b157dc160aa.tar.gz
nng-50e1484af0d443b46aa04fd4a8096b157dc160aa.tar.bz2
nng-50e1484af0d443b46aa04fd4a8096b157dc160aa.zip
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.
Diffstat (limited to 'src/core/event.c')
-rw-r--r--src/core/event.c21
1 files changed, 16 insertions, 5 deletions
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 <string.h>
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;