diff options
author | Konstantin Belousov <kib@FreeBSD.org> | 2015-03-29 19:14:41 +0000 |
---|---|---|
committer | Konstantin Belousov <kib@FreeBSD.org> | 2015-03-29 19:14:41 +0000 |
commit | b072e86d0917ad6e699a6770c44130f7685b4605 (patch) | |
tree | f2378370e64064c1b5148b3b1f49d982f313b08b /lib/libthr/thread/thr_syscalls.c | |
parent | fd78c994f597a9f26dedba0ebaf7598879e31c89 (diff) | |
download | src-b072e86d0917ad6e699a6770c44130f7685b4605.tar.gz src-b072e86d0917ad6e699a6770c44130f7685b4605.zip |
Make kevent(2) a cancellation point.
Note that to cancel blocked kevent(2) call, changelist must be empty,
since we cannot cancel a call which already made changes to the
process state. And in reverse, call which only makes changes to the
kqueue state, without waiting for an event, is not cancellable. This
makes a natural usage model to migrate kqueue loop to support
cancellation, where existing single kevent(2) call must be split into
two: first uncancellable update of kqueue, then cancellable wait for
events.
Note that this is ABI-incompatible change, but it is believed that
there is no cancel-safe code that relies on kevent(2) not being a
cancellation point. Option to preserve the ABI would be to keep
kevent(2) as is, but add new call with flags to specify cancellation
behaviour, which only value seems to add complications.
Suggested and reviewed by: jilles
Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Notes
Notes:
svn path=/head/; revision=280818
Diffstat (limited to 'lib/libthr/thread/thr_syscalls.c')
-rw-r--r-- | lib/libthr/thread/thr_syscalls.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/libthr/thread/thr_syscalls.c b/lib/libthr/thread/thr_syscalls.c index 10fbad4a2ad0..e71bf4ae91c8 100644 --- a/lib/libthr/thread/thr_syscalls.c +++ b/lib/libthr/thread/thr_syscalls.c @@ -341,6 +341,29 @@ __thr_pselect(int count, fd_set *rfds, fd_set *wfds, fd_set *efds, return (ret); } +static int +__thr_kevent(int kq, const struct kevent *changelist, int nchanges, + struct kevent *eventlist, int nevents, const struct timespec *timeout) +{ + struct pthread *curthread; + int ret; + + if (nevents == 0) { + /* + * No blocking, do not make the call cancellable. + */ + return (__sys_kevent(kq, changelist, nchanges, eventlist, + nevents, timeout)); + } + curthread = _get_curthread(); + _thr_cancel_enter(curthread); + ret = __sys_kevent(kq, changelist, nchanges, eventlist, nevents, + timeout); + _thr_cancel_leave(curthread, ret == -1 && nchanges == 0); + + return (ret); +} + /* * Cancellation behavior: * Thread may be canceled at start, but if the system call got some data, @@ -599,6 +622,7 @@ __thr_interpose_libc(void) SLOT(writev); SLOT(spinlock); SLOT(spinunlock); + SLOT(kevent); #undef SLOT *(__libc_interposing_slot( INTERPOS__pthread_mutex_init_calloc_cb)) = |