iv_handle: List handling bugfix for iv_handle_unregister().

iv_handle_unregister() should be using iv_list_del_init() instead
of iv_list_del() for taking iv_handle structs off the global list,
as otherwise, iv_handle_registered() will keep reporting the handle
as being registered, and iv_handle_register() will abort because it
thinks the handle is still registered.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
iv_fd_kqueue: Avoid zeroing kevent array before calling kevent().

This was done to work around valgrind (incorrectly) reporting use
of uninitialised data, but since there is a performance impact to
doing this, we should just live with the false positives.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
Add ARRAY_SIZE() and use it in various places.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
Remove calls to barrier() and the function itself.

As we don't really support accessing the ivykis thread-local state
from signal handlers anyway, we don't really need this.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
iv_time_win32: Some optimisations.

The result of QueryPerformanceFrequency() doesn't change at runtime,
so we only need to call it once at startup time.

Also, we can avoid doing 64bit-by-32bit divisons and the need for
GetTickCount64() by storing a copy of the last tick count value
divided by 1000 in a global variable and handling subsequent calls
to iv_time_get() as incremental updates of the tick count value.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
iv_fd_poll: Minor optimization in the notify_fd logic.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
iv_fd_kqueue: Synchronous fd registration semantics change.

At some point in the FreeBSD 9.0-STABLE cycle, /dev/klog became
pollable via kqueue(), but only in the read direction, and attempts
to register an EVFILT_WRITE filter fail with -EINVAL (while in
9.0-RELEASE, attempts to register EVFILT_READ or EVFILT_WRITE filters
on /dev/klog both return -ENODEV).

This would cause iv_fd_register_try() on a /dev/klog file descriptor
without handlers specified to return failure, as an attempt to
register both an EVFILT_READ and an EVFILT_WRITE filter in one
kevent() call would return -EINVAL, causing iv_fd_kqueue to think
that both registrations failed, while the EVFILT_READ one in fact
succeeded, and this would then cause kevent() to start returning
events for a file descriptor we didn't know we had registered.

Work around this by registering EVFILT_READ and EVFILT_WRITE filters
in separate kevent() calls, and return success from
iv_fd_register_try() if one of those filter registrations succeeds.

This was reported on syslog-ng 3.3 on FreeBSD 9.0-STABLE, and was
reproduced on 9.1-RC1 and 9.1-RC2.

Reported-by: Attila Nagy <bra@fsn.hu>
Reported-by: Gergely Nagy <algernon@balabit.hu>
Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
iv_handle: Minor poll thread signaling optimization.

The handle based main loop executes handle callbacks and then signals
the poll threads for those handles to continue polling, and contains
an optimization to omit signaling the poll thread if the callback has
set the handler function for this handle to NULL.

We can optimize this further by detecting the case where the handle
callback sets the handler to a NULL value and then back to a non-NULL
value -- in this case we also do not need to signal the poll thread,
as it will have been stopped and restarted, and will thus already be
polling on the handle again.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
iv_timer: Rework to allow variable radix tree depth.

Add or remove levels from the radix tree as needed, and make the
radix tree nodes smaller by default (256 instead of 1024 entries),
to conserve memory when only a small number of timers is in use.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
Bump version number to 0.36.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>