client: Add wl_event_queue for multi-thread dispatching
This introduces wl_event_queue, which is what will make multi-threaded wayland clients possible and useful. The driving use case is that of a GL rendering thread that renders and calls eglSwapBuffer independently of a "main thread" that owns the wl_display and handles input events and everything else. In general, the EGL and GL APIs have a threading model that requires the wayland client library to be usable from several threads. Finally, the current callback model gets into trouble even in a single threaded scenario: if we have to block in eglSwapBuffers, we may end up doing unrelated callbacks from within EGL. The wl_event_queue mechanism lets the application (or middleware such as EGL or toolkits) assign a proxy to an event queue. Only events from objects associated with the queue will be put in the queue, and conversely, events from objects associated with the queue will not be queue up anywhere else. The wl_display struct has a built-in event queue, which is considered the main and default event queue. New proxies are associated with the same queue as the object that created them (either the object that a request with a new-id argument was sent to or the object that sent an event with a new-id argument). A proxy can be moved to a different event queue by calling wl_proxy_set_queue(). A subsystem, such as EGL, will then create its own event queue and associate the objects it expects to receive events from with that queue. If EGL needs to block and wait for a certain event, it can keep dispatching event from its queue until that events comes in. This wont call out to unrelated code with an EGL lock held. Similarly, we don't risk the main thread handling an event from an EGL object and then calling into EGL from a different thread without the lock held.
Showing with 123 additions and 35 deletions