From 3c9b318c047c0ec2397401ea329f59aa64690cf5 Mon Sep 17 00:00:00 2001
From: Zebediah Figura <z.figura12@gmail.com>
Date: Tue, 19 Jun 2018 11:27:58 -0500
Subject: [PATCH 53/83] server: Create eventfd descriptors for
 console_input_events objects.

---
 server/console.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/server/console.c b/server/console.c
index 059839e06..c32270855 100644
--- a/server/console.c
+++ b/server/console.c
@@ -38,6 +38,7 @@
 #include "unicode.h"
 #include "wincon.h"
 #include "winternl.h"
+#include "esync.h"
 
 struct screen_buffer;
 struct console_input_events;
@@ -96,6 +97,7 @@ static const struct object_ops console_input_ops =
 static void console_input_events_dump( struct object *obj, int verbose );
 static void console_input_events_destroy( struct object *obj );
 static int console_input_events_signaled( struct object *obj, struct wait_queue_entry *entry );
+static int console_input_events_get_esync_fd( struct object *obj, enum esync_type *type );
 
 struct console_input_events
 {
@@ -103,6 +105,7 @@ struct console_input_events
     int			  num_alloc;   /* number of allocated events */
     int 		  num_used;    /* number of actually used events */
     struct console_renderer_event*	events;
+    int                   esync_fd;    /* esync file descriptor (signalled when events present) */
 };
 
 static const struct object_ops console_input_events_ops =
@@ -113,7 +116,7 @@ static const struct object_ops console_input_events_ops =
     add_queue,                        /* add_queue */
     remove_queue,                     /* remove_queue */
     console_input_events_signaled,    /* signaled */
-    NULL,                             /* get_esync_fd */
+    console_input_events_get_esync_fd,/* get_esync_fd */
     no_satisfied,                     /* satisfied */
     no_signal,                        /* signal */
     no_get_fd,                        /* get_fd */
@@ -253,6 +256,13 @@ static int console_input_events_signaled( struct object *obj, struct wait_queue_
     return (evts->num_used != 0);
 }
 
+static int console_input_events_get_esync_fd( struct object *obj, enum esync_type *type )
+{
+    struct console_input_events *evts = (struct console_input_events *)obj;
+    *type = ESYNC_MANUAL_SERVER;
+    return evts->esync_fd;
+}
+
 /* add an event to the console's renderer events list */
 static void console_input_events_append( struct console_input* console,
 					 struct console_renderer_event* evt)
@@ -307,6 +317,9 @@ static void console_input_events_get( struct console_input_events* evts )
                  (evts->num_used - num) * sizeof(evts->events[0]) );
     }
     evts->num_used -= num;
+
+    if (do_esync() && !evts->num_used)
+        esync_clear( evts->esync_fd );
 }
 
 static struct console_input_events *create_console_input_events(void)
@@ -316,6 +329,10 @@ static struct console_input_events *create_console_input_events(void)
     if (!(evt = alloc_object( &console_input_events_ops ))) return NULL;
     evt->num_alloc = evt->num_used = 0;
     evt->events = NULL;
+    evt->esync_fd = -1;
+
+    if (do_esync())
+        evt->esync_fd = esync_create_fd( 0, 0 );
     return evt;
 }
 
-- 
2.20.1

