Commit Graph
34 Commits
Author SHA1 Message Date
David Herrmann 5e509aad41 eloop: add child-reaper event sources
If multiple childs die simultaneously, only a single SIGCHLD is queued.
Only after our process got scheduled and we unqueued the SIGCHLD, a next
signal can be queued. Therefore, using SIGCHLD as indicator that a
specific child died does not work reliably.

Instead, we must use waitpid() to wait for childs. Hence, we introduce a
new event-source which does that. It reports the PID/status combination
for each child to the registered callbacks.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-12-02 15:06:00 +01:00
David Herrmann ae97bbf7e3 eloop: allow edge-triggered operation
A new EV_ET flag allows ev_fd sources to operate in edge-triggered instead
of level-triggered mode. See epoll(7) for more information.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-11-28 17:46:18 +01:00
David Herrmann d3a0358797 eloop: add ev_timer_drain() helper
This helper reads the current expiration-count from a timer. This can be
used when waking up from an idle-period or similar to reset the timer.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-09-18 16:24:06 +02:00
David Herrmann 246595ab5a eloop: add pre-cbs
pre-cbs are similar to post-cbs but they are called _before_ the actual
dispatching takes place. It can be used to perform any actions before
going to sleep.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-09-11 16:37:30 +02:00
David Herrmann cf318f710e eloop: add post-dispatch hook
When integrating other event-sources or event-loops into eloop which do
not provide FD-abstractions, we often want to check for specific
conditions before returning from the dispatch-callback or going to sleep.
Therefore, you can now register a post-dispatch-cb and check whether your
alien event source is firing. If it is, simply push an idle-source into
the event-loop and it will fire during the next dispatch without going to
sleep.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-09-09 16:14:50 +02:00
David Herrmann 014c468829 eloop: add ev_eloop_get_fd()
This new helper allows retrieving a single file descriptor which
represents the whole event loop. This is very useful if you want to use
your own event loop in combination with libeloop.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-09-09 15:01:32 +02:00
David Herrmann 7ae88d4ed7 eloop: finish documentation
Finish source code documentation. gtk-doc isn't working very well so this
probably needs to be re-done, but not now...

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-08-10 18:01:14 +02:00
David Herrmann 0f19a8496d eloop: move to llog
Move every use of log_* to llog_* and make all objects aware of llog
objects.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-06-24 18:53:46 +02:00
David Herrmann 43eb459cf6 eloop: require llog function in eloop-creation
When creating a new eloop object, we now require an lloop function so we
can perform conditional logging.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-06-24 17:57:38 +02:00
David Herrmann f10ca03eab eloop: allow enabling/disabling counter sources
Similar to fd and timer sources we now also support disabling counter
sources via similar functions.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-05-19 12:26:55 +02:00
David Herrmann 6a0742465b eloop: allow enabling/disabling timer sources
Similar to the fd_enable/disable functions we now also allow the same
operations on timer sources.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-05-19 12:24:28 +02:00
David Herrmann 9703ee3502 eloop: correctly forward error codes
Instead of ignoring epoll errors we should forward them to the caller. The
caller can then still decide to ignore errors.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-05-19 12:15:51 +02:00
David Herrmann 3ca31d922b eloop: allow enabling/disabling fd sources
We sometimes want to be able to enable/disable an fd-source without
allocating memory (for a short period, for instance). Therefore, introduce
two new functions to enable and disable an fd source.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-05-18 17:35:18 +02:00
David Herrmann d1870df383 eloop: move callback declarations into correct order
Use same order as the function definitions.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-05-18 16:42:27 +02:00
David Herrmann 3219b9ccfd eloop: convert idle sources to hooks
Instead if implementing complex idle sources we now provide a hook so
other subsystems can register callbacks.

This simplifies the code a lot and doesn't drop any major functionality.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-05-17 18:35:00 +02:00
David Herrmann 83ed40f089 eloop: move code
Restructure eloop code. This puts stuff more closely together if it is
related.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-05-17 18:17:52 +02:00
David Herrmann e37f4a9fba eloop: make timers create fd on initialization
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-17 17:40:14 +02:00
David Herrmann 69dcfe8586 eloop: take fd argument for fd-sources at initialization
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-17 17:03:46 +02:00
David Herrmann 31550f3180 eloop: add counter sources
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-17 16:48:43 +02:00
David Herrmann 32baeeec9d eloop: add ev_fd_is_bound() helper
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-17 16:33:47 +02:00
David Herrmann f7b398a34a eloop: allow flushing an fd
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-05-05 17:13:42 +02:00
David Herrmann 21f6bbb15d eloop: remove old signal sources
Remove the old non-shared signal sources in favor of shared-signals.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-03-25 17:59:58 +02:00
David Herrmann 580b0a7992 eloop: add shared signal callbacks
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-25 17:39:55 +02:00
David Herrmann 205ab68ff9 eloop: add ev_eloop_run() function
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-23 17:32:45 +01:00
David Herrmann 14b0035f50 eloop: several fixes
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-23 17:13:01 +01:00
David Herrmann 56659ce429 eloop: remove ev_eloop_get_fd()
This function was never used so remove it.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-03-23 16:46:22 +01:00
David Herrmann be8fe301f9 eloop: allow an eloop to be an event source
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-23 16:10:53 +01:00
David Herrmann e7e0744e6e eloop: rename from kmscon_ to ev_
We don't need the long kmscon_ prefix so make it shorter.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-03-20 19:01:28 +01:00
Ran Benita fb14273bf7 eloop: add timer support
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-02-01 22:35:54 +01:00
Ran Benita e823d283c5 eloop: allow reporting error conditions
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-11 13:28:12 +01:00
David Herrmann 39b3cc1237 Eloop: Fix function name typo
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2011-12-03 16:38:14 +01:00
David Herrmann 1fb4c71895 Eloop: Pass mask argument to fd callbacks
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-03 12:22:36 +01:00
David Herrmann 42a6c76e28 Eloop: Add idle-event support
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-03 12:04:29 +01:00
David Herrmann fe5b180fbb Add event loop
Add event loop implementation with support for fd's and signal's through
signalfd.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2011-12-03 11:42:41 +01:00