summaryrefslogtreecommitdiffstats
path: root/src/event-loop.c
Commit message (Collapse)AuthorAgeFilesLines
* 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