Always allocate an event queue
authorPeter Hutterer <peter.hutterer@who-t.net>
Tue, 24 Dec 2013 03:50:10 +0000 (13:50 +1000)
committerJonas Ådahl <jadahl@gmail.com>
Tue, 7 Jan 2014 20:28:08 +0000 (21:28 +0100)
On the typical setup we have at least 3 events pending as soon as we hook it
up (seat added, device added, capability). In the udev case we get up to > 64
events without even having input events on my laptop with only two extra
devices connected. So always allocate an event buffer to avoid spurious
resizing.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
src/libinput.c

index 95976f7..06b7263 100644 (file)
@@ -372,6 +372,13 @@ libinput_init(struct libinput *libinput,
        if (libinput->epoll_fd < 0)
                return -1;
 
+       libinput->events_len = 4;
+       libinput->events = zalloc(libinput->events_len * sizeof(*libinput->events));
+       if (!libinput->events) {
+               close(libinput->epoll_fd);
+               return -1;
+       }
+
        libinput->interface = interface;
        libinput->user_data = user_data;
        list_init(&libinput->source_destroy_list);
@@ -869,10 +876,7 @@ libinput_post_event(struct libinput *libinput,
 
        events_count++;
        if (events_count > events_len) {
-               if (events_len == 0)
-                       events_len = 4;
-               else
-                       events_len *= 2;
+               events_len *= 2;
                events = realloc(events, events_len * sizeof *events);
                if (!events) {
                        fprintf(stderr, "Failed to reallocate event ring "