Always allocate an event queue

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>
This commit is contained in:
Peter Hutterer 2013-12-24 13:50:10 +10:00 committed by Jonas Ådahl
parent faee8fe1a7
commit c0ac1ef9f2

View 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 "