aboutsummaryrefslogtreecommitdiffstats
path: root/src/event-loop.c
Commit message (Collapse)AuthorAgeFilesLines
* event-loop: Use timespec utils instead of hand-rolling our ownSebastian Wick2025-02-041-54/+7
| | | | Signed-off-by: Sebastian Wick <sebastian.wick@redhat.com>
* src: Finish assert() clean-upDerek Foreman2024-08-091-1/+0
| | | | | | | | | | | | | From cleanup commit 0cecde304: assert()s can be compiled away by #defining NDEBUG. Some build systems do this. Using wl_abort gives a human readable error message and it isn't compiled away. That commit missed one final assert, presumably due to missing it with grep because of a coding style issue. Fix that up, and remove inclusion of <assert.h> as appropriate. Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
* src: switch asserts to wl_abortmeltq2024-07-111-2/+4
| | | | | | | | assert()s can be compiled away by #defining NDEBUG. Some build systems do this. Using wl_abort gives a human readable error message and it isn't compiled away. This commit closes issue #230. Signed-off-by: meltq <tejasvipin76@gmail.com>
* event-loop: use wl_priv_signal for the destroy signalKirill Primak2024-02-081-5/+6
| | | | Signed-off-by: Kirill Primak <vyivel@eclair.cafe>
* event-loop: optimize timer check logicYang Wang2023-05-031-1/+3
| | | | | | | the 'has_timers' flag can be returned directly without having to track all the ready events when a timer is found ready. Signed-off-by: Yang Wang <KevinYang.Wang@amd.com>
* event-loop: Handle EINTR and EAGAIN in wl_event_loop_dispatchJoshua Ashton2023-05-021-1/+76
| | | | | | | | | | | This fixes an issue where it was not possible to start Gamescope under GDB on some setups. https://github.com/ValveSoftware/gamescope/issues/743 Any signals would cause epoll_wait to return -1 and set errno to EINTR. This also handles the EAGAIN case like the other polling loops in libwayland. Signed-off-by: Joshua Ashton <joshua@froggi.es>
* Use zalloc for structsSimon Ser2022-02-051-5/+5
| | | | | | | | When allocating memory for structs, use zalloc instead of malloc. This ensures the memory is zero-initialized, and reduces the risk of forgetting to initialize all struct fields. Signed-off-by: Simon Ser <contact@emersion.fr>
* src: Add missing new lines to log messagesMarius Vlad2021-05-071-4/+4
| | | | Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
* event-loop: Track timer event sources in userspaceManuel Stoeckl2020-01-211-29/+415
| | | | | | | | | | | | | libwayland now uses only one file descriptor to keep track of all the timer event sources associated with an event loop. An array-based binary heap is used to determine which event source has the earliest deadline. (Previously, each timer event source had its own timerfd, making it easy for the a process using many timer event sources to run out of file descriptors.) Signed-off-by: Manuel Stoeckl <code@mstoeckl.com>
* Use wl_container_of internallyMichael Forney2019-06-051-2/+2
| | | | | | | | | Rather than have two versions of the macro with slightly different interfaces, just use wl_container_of internally. This also removes use of statement expressions, a GNU C extension. Signed-off-by: Michael Forney <mforney@mforney.org>
* log: remove "%m" from format strings by using strerror(errno)Antonio Borneo2019-05-021-2/+2
| | | | | | | | | | | | | | | | | The printf() format specifier "%m" is a glibc extension to print the string returned by strerror(errno). While supported by other libraries (e.g. uClibc and musl), it is not widely portable. In Wayland code the format string is often passed to a logging function that calls other syscalls before the conversion of "%m" takes place. If one of such syscall modifies the value in errno, the conversion of "%m" will incorrectly report the error string corresponding to the new value of errno. Remove all the occurrences of the specifier "%m" in Wayland code by using directly the string returned by strerror(errno). Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
* eventloop: clarify post_dispatch_check()Christopher James Halse Rogers2017-12-041-10/+16
| | | | | | | | | | | | | This *technically* changes the semantics of the return value of the source callbacks. Previously you could return a negative number from a source callback and it would prevent *other* source callbacks from triggering a subsequent recheck. Doing that seems like such a bad idea it's not worth supporting. v2: Log this case if it is hit, so we don't silently change behaviour. Signed-off-by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com> Reviewed-by: Daniel Stone <daniels@collabora.com>
* server: document wl_event_loop and wl_event_sourcePekka Paalanen2017-08-251-1/+243
| | | | | | | | | | | This documents all the public API related to wl_event_loop and wl_event_source objects. Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk> Reviewed-by: Yong Bakos <ybakos@humanoriented.com> [Pekka: fixed typos pointed by Yong] [Pekka: fixed typos pointed by Christopher] Reviewed-By: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
* (multiple): Include stdint.hYong Bakos2016-07-251-0/+1
| | | | | | | | | | Some headers and source files have been using types such as uint32_t without explicitly including stdint.h. Explicitly include stdint.h where appropriate. Signed-off-by: Yong Bakos <ybakos@humanoriented.com> Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
* server-core, event-loop: Fix parameter alignment.Yong Bakos2016-06-071-4/+4
| | | | | Signed-off-by: Yong Bakos <ybakos@humanoriented.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
* event-loop: Include wayland-util.hYong Bakos2016-06-071-0/+1
| | | | | | | | | | | event-loop.c uses WL_EXPORT and wl_list, which are defined in wayland-util.h. Include wayland-util.h explicitly, rather than transitively through wayland-server-core.h. Signed-off-by: Yong Bakos <ybakos@humanoriented.com> Reviewed-by: Sam Spilsbury <smspillaz@gmail.com>
* event-loop: Make transitive include explicitYong Bakos2016-06-011-1/+1
| | | | | | | | The explicit inclusion of wayland-server.h hides the real dependency, which is wayland-server-core.h. Signed-off-by: Yong Bakos <ybakos@humanoriented.com> Reviewed-by: Jonas Ådahl <jadahl@gmail.com>
* event-loop: remove extra headerMarek Chalupa2015-11-161-1/+0
| | | | | | | we don't use assert() anywhere in this file, so remove #include <assert.h> Signed-off-by: Marek Chalupa <mchqwerty@gmail.com> Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
* cosmetic: gratuitous whitespace changes in event-loop.cDerek Foreman2015-06-231-1/+1
| | | | | | Signed-off-by: Derek Foreman <derekf@osg.samsung.com> Reviewed-by: Jon A. Cruz <jonc@osg.samsung.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
* src: Update boilerplate from MIT X11 license to MIT Expat licenseBryce Harrington2015-06-121-16/+19
| | | | | Signed-off-by: Bryce Harrington <bryce@osg.samsung.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
* event-loop: Dispatch idle callbacks twiceDerek Foreman2015-01-281-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | To fix a shutdown crash in weston's x11 compositor I want to move the weston X window close to an idle handler. Since idle handlers are processed at the start of an event loop, the handler that deals with window close will run at the start of the next input_loop dispatch, after which the dispatcher blocks on epoll forever (since all input events that will ever occur have been consumed). Dispatching idle callbacks both at the start and end of event-loop processing will prevent this permanent blocking. Note that just moving the callback dispatch could theoretically result in an idle callback being delayed indefinitely while waiting for epoll_wait() to complete. Callbacks are removed from the list when they're run, so the second dispatch won't result in any extra calls. Signed-off-by: Derek Foreman <derekf@osg.samsung.com> Reviewed-by: Giulio Camuffo <giuliocamuffo@gmail.com> Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
* event-loop.c: Use correct OS abstraction function for dupfd()Philip Withnall2014-11-051-1/+1
| | | | | | | | Signed-off-by: Philip Withnall <philip at tecnocode.co.uk> Signed-off-by: Karsten Otto <ottoka at posteo.de> Reviewed-by: David Fort <contact at hardening-consulting.com> Reviewed-by: Marek Chalupa <mchqwerty@gmail.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
* event-loop: make signalfd non-blockingMarek Chalupa2014-08-181-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | When we add more that one source to a signal, then wayland will block in wl_event_loop_dispatch. This is due to the attampt to read from signal's fd each time the source is dispatched. wl_event_loop_add_signal(loop, SIGINT, ...); wl_event_loop_add_signal(loop, SIGINT, ...); /* raise signal .. */ /* we got two fd's ready, both for the one SIGINT */ epoll_wait(...) = 2 [ for (i == 0) ] source1->dispatch() --> read(fd1); [ for (i == 1) ] source2->dispatch() --> read(fd2); /* blocking! */ Reading from fd2 will block, because we got only one signal, and it was read from fd1. Signed-off-by: Marek Chalupa <mchqwerty@gmail.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
* Avoid printing to stderrKristian Høgsberg2014-04-301-6/+3
| | | | | | | Use wl_log in the last few places where we print to stderr. Remove logging in a couple of places where we properly return an error code. https://bugs.freedesktop.org/show_bug.cgi?id=73339
* Use non-blocking timerfd to prevent blocking when updating timer event sourcesAndrew Wedgbury2014-04-251-2/+3
| | | | | | | | | | | | | | | | | This implements a simple fix for the blocking problem that occurs when updating a timer event source after the timer expires, but before its callback is dispatched. This can happen when another event happens during the same epoll wakeup as the timer event, and causes the read() call in wl_event_source_timer_dispatch() to block for the updated duration of the timer. We never want this read() call to block, so I believe it makes sense for the timerfd to be non-blocking, and we simply ignore the case where the read fails with EAGAIN. We still report all other errors as before, and still ignore the actual value read from the socket. With this change, the event_loop_timer_updates unit test case I submitted previously now passes, and weston appears to work as before.
* server: Make wl_object and wl_resource opaque structsKristian Høgsberg2013-07-021-1/+1
| | | | | | | | | | With the work to add wl_resource accessors and port weston to use them, we're ready to make wl_resource and wl_object opaque structs. We keep wl_buffer in the header for EGL stacks to use, but don't expose it by default. In time we'll remove it completely, but for now it provides a transition paths for code that still uses wl_buffer. Reviewed-by: Jason Ekstrand<jason@jlekstrand.net>
* event-loop: fix returning the destroy-signal listenerDavid Herrmann2013-01-241-1/+1
| | | | | | | We need to actually return the destroy-listener, otherwise the return value is undefined. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
* Add a destroy signal to the wl_event_loop objectJason Ekstrand2013-01-151-0/+21
|
* Move ARRAY_LENGTH out of public headersKristian Høgsberg2012-10-191-0/+1
| | | | | | | | Exporting unprefixed symbols is a pretty bad idea so don't do that. Instea of redefining it WL_ARRAY_LENGTH, we just move the define to our private header. The scanner generates code that uses ARRAY_LENGTH, but we can just make it count the number elements and emit an integer constant instead.
* Change filedescriptor API to be thread safeKristian Høgsberg2012-10-101-0/+4
| | | | | | | | | | | | | | | | | | | | | The update callback for the file descriptors was always a bit awkward and un-intuitive. The idea was that whenever the protocol code needed to write data to the fd it would call the 'update' function. This function would adjust the mainloop so that it polls for POLLOUT on the fd so we can eventually flush the data to the socket. The problem is that in multi-threaded applications, any thread can issue a request, which writes data to the output buffer and thus triggers the update callback. Thus, we'll be calling out with the display mutex held and may call from any thread. The solution is to eliminate the udpate callback and just require that the application or server flushes all connection buffers before blocking. This turns out to be a simpler API, although we now require clients to deal with EAGAIN and non-blocking writes. It also saves a few syscalls, since the socket will be writable most of the time and most writes will complete, so we avoid changing epoll to poll for POLLOUT, then write and then change it back for each write.
* event-loop: export wl_event_loop_dispatch_idle()David Herrmann2012-09-121-3/+3
| | | | | | | | | | | | | | | | | | | | When integrating the wayland event-loop into another event-loop, we currently have no chance of checking whether there are pending idle sources that have to be called. This patch exports the "dispatch_idle_sources()" call so other event loops can call this before going to sleep. This is what wl_event_loop_dispatch() currently does so we simply allow external event-loops to do the same now. To avoid breaking existing applications, we keep the call to dispatch_idle_sources() in wl_event_loop_dispatch() for now. However, if we want we can remove this later and require every application to call this manually. This needs to be discussed, but the overhead is negligible so we will probably leave it as it is. This finally allows to fully integrate the wayland-server API into existing event-loops without any nasty workarounds. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
* event-loop: remove dead codeDavid Herrmann2012-09-101-2/+2
| | | | | | | There is really no need to increment "n" if we never read the value. The do-while() loop overwrites the value before it is read the first time. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
* event-loop: Delete fd from epoll when removing event sourceKristian Høgsberg2012-05-081-2/+6
| | | | | | | Closing an fd will remove it from the epoll set only if it hasn't been dup'ed. In other words, the fd is only removed from epoll when all file descriptors referring to the open file has been close. We now dup fd for fd sources, so we need to use EPOLL_CTL_DEL directly now.
* event-loop: Consolidate code for setting up new sourcesKristian Høgsberg2012-05-081-98/+44
|
* event-loop: fix conditional checkingTiago Vignatti2012-05-081-1/+1
| | | | | | | | | Introduced in: commit 80f4f0d5127ebc8d5e35969a29691cf61a79997d Author: Jonas Ådahl <jadahl@gmail.com> Date: Wed Mar 21 10:31:24 2012 +0100 Signed-off-by: Tiago Vignatti <tiago.vignatti@intel.com>
* os: wrap epoll_createPekka Paalanen2012-04-251-1/+2
| | | | | | | | | Some system C libraries do not have epoll_create1() nor EPOLL_CLOEXEC, provide a fallback. Add tests for the wrapper. Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
* event-loop: Use two-step destruction of event loop sources.Jonas Ådahl2012-03-211-50/+49
| | | | | | | | | | | | Instead of directly freeing an event source upon removal put it in a queue later handled by the event loop; either after a dispatch or upon event loop destruction. This is necessary to avoid already queued up event sources to be freed during some other dispatch callback, causing segmentation faults when the event loop later tries to handle an event from the freed source. Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
* event-loop: always do the post-dispatch checkAnder Conselvan de Oliveira2012-03-201-1/+2
| | | | | The post-dispatch check on wl_event_loop_dispatch() was not being run if epoll_wait returned 0 events, making the check unreliable.
* Fix WL_EVENT_WRITEABLE typoKristian Høgsberg2011-12-281-3/+3
|
* event-loop: Fix idle handler dispatch corner caseKristian Høgsberg2011-10-291-2/+4
| | | | | | | | | When the last idle handler queues another idle handler, we fail to dispatch that last handler. The wl_list_for_each_safe loop looks up the next pointer before running the handler, and at that point it points to the head of the list and the loop terminates. Instead, just loop until the list is empty.
* event-loop: Quiet a few warningsKristian Høgsberg2011-08-121-2/+10
| | | | There's no good error recovery possible in these cases though.
* Rename source subdir from wayland to srcKristian Høgsberg2011-08-121-0/+465