summaryrefslogtreecommitdiff
path: root/src/eloop.c
AgeCommit message (Collapse)AuthorFilesLines
2012-05-17eloop: move codeDavid Herrmann1-409/+425
Restructure eloop code. This puts stuff more closely together if it is related. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-05-17eloop: make timers create fd on initializationDavid Herrmann1-76/+111
Similar to other event sources we now initialize internal data on timer creation instead of when the source is added to the loop. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-05-17eloop: take fd argument for fd-sources at initializationDavid Herrmann1-85/+85
When creating a new fd-source you must supply the file descriptor directly. You cannot delay this to the time when you add the fd to the event loop. This simplifies the logic and allows much smoother handling in the event loop core. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-05-17eloop: add counter sourcesDavid Herrmann1-0/+195
Counter sources are based on the eventfd syscall of linux. Internally, is uses a 64bit counter which is initialized to 0 and can be increased by the caller. Whenever the value is non-zero, the fd is marked readable and we call our callback. We read the 64bit integer (which resets it to 0) and pass the current value to the callback. This can be used to implement cross-process notification methods or to have idle-sources as valid file-descriptors in an epoll set which could be exported to other applications that are not compliant to our event loop. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-05-17eloop: add ev_fd_is_bound() helperDavid Herrmann1-0/+5
This helper returns true if the fd is bound to an eloop object, otherwise false is returned. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-05-05eloop: allow flushing an fdDavid Herrmann1-0/+13
Sometimes one wants to remove all pending events for an fd. The new ev_eloop_flush_fd() call allows this in a safe way. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-04-22eloop: fix memory leak for shared signalsDavid Herrmann1-0/+2
A shared signal owns an eloop_fd object. This has a reference of its connected eloop. Therefore, we must free a shared signal to drop a reference to the connected eloop and cannot postpone this to eloop-destruction. Otherwise, the eloop will never get destroyed. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-04-22eloop: use kmscon_dlist for shared signalsDavid Herrmann1-9/+16
Move to new list-implementation instead of the single-linked list. This allows removal of elements in O(1). Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-03-25eloop: wait for all childsDavid Herrmann1-0/+30
Move child-waiting into the eloop subsystem so all childs are always correctly freed. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-03-25eloop: remove old signal sourcesDavid Herrmann1-142/+0
Remove the old non-shared signal sources in favor of shared-signals. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-03-25use pthread_sigmask instead of sigprocmaskDavid Herrmann1-2/+3
pthread is already in our vmem due to our dependencies so link to it explicitly and use pthread_sigmask to avoid buggy sigprocmask in multi-threaded applications. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-03-25eloop: add shared signal callbacksDavid Herrmann1-0/+153
Our current signal source has the problem that a single signal event is only delivered to one random registered source. This is the design of the signalfd kernel feature. However, for signals like SIGCHLD it is often desired to have multiple callbacks. Hence, while keeping the old signal-source, we now also allow a shared signal source. It is registered the same way as the old signal source but uses a shared hook. We may remove the old source so we don't use it in the new implementation. There are still problems when multiple eloops are used in a single process and you register the same shared-signum in both eloops. However, such a design is bad anyway, so we don't care. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-03-25eloop: catch EINTR in epoll_wait()David Herrmann1-2/+6
epoll_wait() returns EINTR even if using SA_RESTART for signals. Therefore, catch EINTR and set count to zero. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-03-23Fix time calculationsDavid Herrmann1-3/+3
eloop.c and log.c use struct timeval to calculate time-diffs but incorrectly use "-" instead of "+" as the value is already negative. They also use unsigned integers so fix both occurences. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-03-23eloop: correctly set ->exitDavid Herrmann1-0/+3
When exiting a child eloop we should forward the exit to the parent. Also, we should reset ->exit on ev_eloop_run() otherwise we cannot run multiple times. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-03-23eloop: add debug messagesDavid Herrmann1-0/+3
Add two debug messages to track eloop behavior. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-03-23eloop: add ev_eloop_run() functionDavid Herrmann1-1/+53
ev_eloop_run() runs the eloop for a given fixed time. If the dispatcher returns and the timeout isn't reached, then the dispatcher is called again. This also adds the *_exit() function which allows to exit the main-loop and can be called from anywhere (including the callbacks). Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-03-23eloop: several fixesDavid Herrmann1-55/+45
Fix parameter validation, fix log_* statements, fix indentation and print messages on HUP/ERR. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-03-23eloop: remove fd from epoll-set on HUPDavid Herrmann1-2/+4
If a handler does not correctly remove itself on HUP, the epoll-loop will never sleep again because the fd will always be notified as HUP. Therefore, remove the fd from the epoll-set directly on HUP. This doesn't change application behavior so it is safe here. This also allows other subsystems to ignore HUP/ERR events if they are not fatal. The FD won't be readded but that may not bother. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-03-23eloop: remove ev_eloop_get_fd()David Herrmann1-8/+0
This function was never used so remove it. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-03-23eloop: allow an eloop to be an event sourceDavid Herrmann1-2/+74
This allows to add one eloop object into another eloop. This is useful if we want to run a single event source isolated (for instance VT on exit). The internal epoll-descriptor allows polling so this is a fairly straightforward implementation. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-03-20eloop: rename from kmscon_ to ev_David Herrmann1-120/+120
We don't need the long kmscon_ prefix so make it shorter. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-01eloop: add timer supportRan Benita1-0/+164
Add support for dispatching events every given interval. timerfd is used for hooking up to the event loop, similar to how signalfd is used. Only relative, monotonic and possibly repeating timer events are supported. It can be enhanced if there's ever a need. Signed-off-by: Ran Benita <ran234@gmail.com> Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-01-24log: move log_warning to log_warnDavid Herrmann1-2/+2
log_warn is much shorter and we already use log_err instead of log_error so this is more consistent now. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-01-24eloop: remove verbose debug messagesDavid Herrmann1-2/+0
These dispatch debug messages are currently no longer needed and just fill the log needlessly. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-01-11eloop: allow reporting error conditionsRan Benita1-0/+2
Add KMSCON_ERR, the equivalent of EPOLLERR. Signed-off-by: Ran Benita <ran234@gmail.com> Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-01-09Fix compiler sign-mismatch warningsRan Benita1-1/+1
Signed-off-by: Ran Benita <ran234@gmail.com> Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-01-09a few cosmetic changesRan Benita1-1/+1
Signed-off-by: Ran Benita <ran234@gmail.com> Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2011-12-03Eloop: Fix function name typoDavid Herrmann1-1/+1
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2011-12-03Eloop: Add debug statementsDavid Herrmann1-1/+7
Add some more debug statements to allow easier eloop monitoring. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2011-12-03Eloop: Pass mask argument to fd callbacksDavid Herrmann1-8/+8
fd-callbacks are pretty useless if we do not pass a mask argument with the current flags. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2011-12-03Eloop: Add idle-event supportDavid Herrmann1-0/+140
Idle events are dispatched everytime kmscon_eloop_dispatch() is called. To allow the callbacks to add/remove/modify all current idle events (including themself), we need to keep a pointer to the currently dispatched event. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2011-12-03Add event loopDavid Herrmann1-0/+439
Add event loop implementation with support for fd's and signal's through signalfd. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>