iv_event: Optimize posting of events belonging to the local thread.

If we're asked to post an iv_event that belongs to the current thread,
register a task to run the current thread's pending iv_event list instead
of posting the iv_event_raw for the current thread.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
iv_work: Remove earlier optimization for race condition fix.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
iv_fd: Update man page to reference iv_fatal(2) instead of abort(3).

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
man3: Clarify that iv_now doesn't refer to the current time-of-day.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
iv_fd_pump: Enable close-on-exec on splice pipe file descriptors.

If pipe2(2) is available, use it to create a pipe where both file
descriptors already have the close-on-exec flag set, otherwise fall
back to using pipe(2) and setting the flag by hand.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
iv_event: Minor iv_event_unregister() optimization.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
iv_event: Minor iv_event_register() optimization.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
Add support for ppoll(2).

For now this is just so that we get higher resolution timeouts than
what is possible with poll(2).

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
iv_fd_pump: Slight simplification in __iv_fd_pump_pump().

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
kqueue: Double amount of event buffering space.

Since each file descriptor can generate up to two kevents, make
sure we have enough space in our event return buffer for at least
2 * st->numfds events.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
Implement fallback version of spinlocks based on pipes.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
configure.ac: Detect __thread support with a runtime test.

To catch the case where the __thread keyword appears to be accepted
but different threads still share the same storage location for
variables marked with __thread, without having to maintain a hardcoded
list of platforms where this happens.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
iv_fd_pump: Treat iv_fd_pump.h as a system include file.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
iv_event_raw_posix: Rework eventfd handling.

The Linux glibc eventfd() wrapper function (around the SYS_eventfd{,2}
system calls) returns EINVAL if it is given a nonzero flags argument
and SYS_eventfd2 (which is the variant of SYS_eventfd that takes a flags
argument) isn't implemented, while iv_event_raw_posix was expecting to
get either ENOSYS or success.

Rework iv_event_raw_posix to first try calling eventfd() with the
O_CLOEXEC and O_NONBLOCK flags, and if that fails due to the running
kernel not supporting SYS_eventfd2, fall back to calling eventfd()
with a zero flags argument (which will call SYS_eventfd) and then
setting the two flags on the returned file descriptor by hand.

Also, if the system call numbers for SYS_eventfd or SYS_eventfd2 are
available, call those system calls by hand using syscall(2) instead of
using the glibc eventfd() wrapper function, as the latter insists on
always trying SYS_eventfd2 first, even if that has already been found
to be not implemented in the running kernel and even if the passed-in
flags argument is zero, so doing the system calls by hand allows us to
skip this useless extra guaranteed-to-fail SYS_eventfd2 system call if
that has returned -ENOSYS before.

Reported by user "Dit" on the Balabit community forums.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
iv_fd_epoll: Don't call epoll_create1() again if it fails with -ENOSYS.

If the running kernel doesn't support epoll_create1(), make a note
of that and don't try calling it again, but instead, immediately fall
back to epoll_create() the next time iv_init() is called.

Also, call the epoll_create1() system call by hand (using syscall(2))
if possible, to attempt to avoid introducing an ELF symbol dependency
on GLIBC_2.9 if possible.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
iv_handle: Unconditionally call iv_invalidate_now() in the poll loop.

To avoid starving the execution of timers when handles are activated
at a higher rate than we can keep up with.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
configure.ac: Add support for automake silent-rules.

Recentish automake supports Linux kernel style silent building, which
makes it easier to see warnings, among other things.  This little
patch tells automake to enable support for silent-rules, but have it
off by default.

If silent building is desired, make V=0 will do the trick.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>