summaryrefslogtreecommitdiff
path: root/src/eloop.c
AgeCommit message (Collapse)AuthorFilesLines
2013-02-11Fix several typosJakub Wilk1-19/+19
Provided via github. Fixes typos in documentation and comments. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2013-02-08llog: add "data" parameter to pass contextDavid Herrmann1-29/+53
If we allow users to specify log functions, we should also allow them to pass a context. This isn't used internally, but may be needed by external users so provide it. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2013-02-06build: major cleanupDavid Herrmann1-0/+59
Major overhaul of the build system. This introduces symbol-versioning for all exported libraries. Please note that none of these libraries is stable, yet! Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2013-01-13eloop: add EV_ONESHOT and EV_SINGLE flags for idle sourcesDavid Herrmann1-6/+16
EV_ONESHOT will remove idle sources once they have been processed and EV_SINGLE will only register the source if it hasn't been registered, yet. For source removal EV_ONESHOT has no effect but EV_SINGLE causes all events with this cb+data combination to be removed. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2013-01-13shl: hook: add 'oneshot' flagDavid Herrmann1-5/+5
If an entry is marked as 'oneshot' then it will get deleted after it has been called once. Note that the entry is unlinked _before_ the callback is called. If you use 'oneshot'-entries and normal entries with the same cb+data combination, then you will probably get unexpected behavior. It is not recommended to do that. In detail, you cannot control which entry is deleted via a shl_hook_rm() call so you can never be sure whether the oneshot entry or a normal entry is deleted. Do not mix oneshot entries with normal entries! Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-12-02eloop: add child-reaper event sourcesDavid Herrmann1-13/+70
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-02eloop: fix memory loop when signal registration failsDavid Herrmann1-1/+7
If the signal-registration fails, we need to destroy it again. Otherwise, it will keep a reference to the current eloop-object and hence it will never get freed. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-11-28eloop: allow edge-triggered operationDavid Herrmann1-1/+5
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-27eloop: fix not disabling sources on EV_HUPDavid Herrmann1-3/+0
We used to disable event sources on EV_HUP to avoid draining the event-queue for non-edge-triggered sources. However, this turns out to be not working with special files so we disable it again. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-10-24eloop: fix ev_fd_update() to do nothing if the mask does not changeDavid Herrmann1-0/+2
If the new mask is equal to the old mask, we shouldn't change anything. This improves performance and avoids syscalls when they aren't needed. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-10-07eloop: fix leaving dead FDs pollableDavid Herrmann1-1/+1
We used to remove dead FDs from the epoll-loop, but we should do this only if they are no longer readable. An FD might be dead/HUP but still readable. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-09-30Fix printf() specified bugs all over the codeDavid Herrmann1-3/+4
When enabling the printf() logic for the logging subsystem, several warnings were produced about missing or wrong specifiers. This fixes all those occurrences. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-09-27eloop: don't warn when removing bad fds from epoll-setDavid Herrmann1-1/+1
People might want to close file-descriptors before destroying the ev_fd object if they actually have no direct control of it. For instance if used through a library. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-09-27eloop: make timerfd non-blockingDavid Herrmann1-1/+1
We actually allow draining a timer so we cannot be sure that a timer has valid data that we can read. We already handle the non-blocking case everywhere, we just missed setting this flag. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-09-27eloop: allow NULL for timer updatesDavid Herrmann1-1/+7
If NULL is passed for timer udpates, we simply assume that the timer should be disarmed and use a zeroed itimerspec. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-09-18eloop: add ev_timer_drain() helperDavid Herrmann1-24/+64
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-18shl: move kmscon_hook_* to shlDavid Herrmann1-32/+32
This is the last static helper that is moved so as a next step we should get rid of the "static" library entirely. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-09-18shl: move llog to shlDavid Herrmann1-1/+1
We might argue whether llog should be kept separate, however, shl is a loose pile of headers and sources so pushing llog into it seems reasonable. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-09-15shl: move dlist to shl_dlist.hDavid Herrmann1-1/+1
Instead of including dlist in the static library, we now move it to SHL. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-09-15shl: move dlist implementation to shl_dlist_*David Herrmann1-12/+12
Shl (Static helper library) is the new name of all static helpers in kmscon that might be shared between different applications. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-09-11eloop: add pre-cbsDavid Herrmann1-1/+60
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-11eloop: call post-cbs on errors during dispatchDavid Herrmann1-8/+12
If the dispatch files or is skipped for whatever reason, we should nevertheless call the post-cbs to avoid any integration errors. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-09-11eloop: fix unregistering post-cbsDavid Herrmann1-1/+1
This is obviously a copy/paste error. This fixes the unregistering to correctly work now. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-09-09eloop: fix registering post-cb hooksDavid Herrmann1-1/+8
We actually have to register the hook-helper before we can add any hooks. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-09-09eloop: improve idle-source logicDavid Herrmann1-85/+124
Instead of using an ev_counter object internally, we now directly create a new eventfd object. This avoids adding/removing the fd from the epoll-set constantly when adding/removing idle sources. This should increase idle-source speed considerably. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-09-09eloop: add post-dispatch hookDavid Herrmann1-0/+52
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-09eloop: add ev_eloop_get_fd()David Herrmann1-0/+20
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-04build: make eloop independent of libkmscon-staticDavid Herrmann1-1/+2
This removes the nasty dependency to libkmscon-static for libeloop. Otherwise, we might end up with GLESv2 dependencies here which is really not what we want. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-08-10eloop: finish documentationDavid Herrmann1-8/+374
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-07-21eloop: prevent recursive dispatchingDavid Herrmann1-0/+4
We do not support recursive dispatching so prevent it explicitely. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-07-21eloop: fix invalid memory access during dispatchDavid Herrmann1-10/+13
We use a temporary array of "to-be-dispatched" event sources while dispatching. However, we incorrectly set the "count" variable so sources may access invalid memory when removing themself from the event loop. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-07-01eloop: fix signal creationDavid Herrmann1-0/+1
The previous fix incorrectly registered new signals always to the last found signal which is definitely incorrect. Therefore, we now correctly traverse the list and register new signals as new signals. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-07-01eloop: silence gcc warningDavid Herrmann1-2/+2
Gcc warns about an uninitialized variable (which technically is correct). However, there is really no way this can really happen. But to make gcc happy (and to enhance code readability) we now depend on !sig whether the list-search was successful. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-06-24static: move statically linked subsystems to static_*David Herrmann1-2/+2
Small stuff that is not worth putting into a separate library is no moved into the "static" library which is statically linked into all our subsystems. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-06-24eloop: move to llogDavid Herrmann1-86/+151
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-24eloop: require llog function in eloop-creationDavid Herrmann1-4/+10
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-23eloop: turn comment into non-gtkdoc commentDavid Herrmann1-1/+1
This comment does not use gtk-doc syntax so remove the extra *. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-05-20eloop: fix eloop object never being freedDavid Herrmann1-5/+35
We must _never_ take a reference to ourself in a constructor. Otherwise, the refcnt will be >1 which means if the user calls *_unref() the object will not get freed. Therefore, do not add the counter object used for idle sources directly to the event loop. Instead, add it when the first idle source is registered and remove it when the last source is removed. This will slightly slow down performance of idle-sources. However, the whole eloop is not optimized for speed, yet, so we don't care for now. Reported-by: Ran Benita <ran234@gmail.com> Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-05-19eloop: add initial gtk-doc commentsDavid Herrmann1-51/+307
Add gtk-doc compatible comments to most of the functions in eloop.c. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-05-19eloop: dynamically reallocate dispatch cacheDavid Herrmann1-14/+46
We do not maintain event caches so we must make sure that every event source gets dispatched. If we call epoll_wait() and our buffer gets filled everytime, then there might be an event source that does not get dispatched because it is always above the buffer range. Therefore, we now dynamically increase the cache size when it once gets filled up. This gets critical if we handle thousands of clients or fds, however, our use case is limited to some system resources and hence does not suffer here. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-05-19eloop: add more commentsDavid Herrmann1-6/+113
Add comments describing each source and the nesting features. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-05-19eloop: use counter source for idle eventsDavid Herrmann1-4/+37
epoll has the great feature that the poll object is an fd itself. However, if we want to use idle-sources, we couldn't add them to the epoll set. Now, we use a counter source for all idle sources so if we add a single event-loop as source to another event loop, the idle sources will get dispatched correctly. Furthermore, we now longer block after handling idle sources but instead now correctly run idle sources every next round without sleeping for fd events in between. Unregister idle sources to avoid hogging the CPU. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-05-19eloop: fix not returning new counter objectDavid Herrmann1-0/+1
We forgot to actually store the pointer to the new counter object in the \out variable. Fix this now. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-05-19eloop: forward timer HUP and I/O errors to callerDavid Herrmann1-3/+16
Similar to counter callbacks we now call timer callbacks with 0 as argument on errors and disable the timer source. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-05-19eloop: forward EOF and I/O errors of counters to callerDavid Herrmann1-3/+16
Instead of silently dropping read() errors we now disable the counter and call the user-supplied callback with 0 as argument so they can react on errors. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-05-19eloop: allow enabling/disabling counter sourcesDavid Herrmann1-0/+21
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-19eloop: allow enabling/disabling timer sourcesDavid Herrmann1-0/+21
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-19eloop: correctly forward error codesDavid Herrmann1-27/+74
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-18eloop: allow enabling/disabling fd sourcesDavid Herrmann1-41/+92
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-17eloop: convert idle sources to hooksDavid Herrmann1-136/+33
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>