summaryrefslogtreecommitdiffstats
path: root/lib/libthr/thread/thr_syscalls.c
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2015-03-29 19:14:41 +0000
committerkib <kib@FreeBSD.org>2015-03-29 19:14:41 +0000
commit6531ee3ae59f5ac0b1ead44cc768dbbb4757a521 (patch)
treef2378370e64064c1b5148b3b1f49d982f313b08b /lib/libthr/thread/thr_syscalls.c
parenteb7a3e863e83a5008845bc3751bc734b7b5928e2 (diff)
downloadFreeBSD-src-6531ee3ae59f5ac0b1ead44cc768dbbb4757a521.zip
FreeBSD-src-6531ee3ae59f5ac0b1ead44cc768dbbb4757a521.tar.gz
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
Diffstat (limited to 'lib/libthr/thread/thr_syscalls.c')
-rw-r--r--lib/libthr/thread/thr_syscalls.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/libthr/thread/thr_syscalls.c b/lib/libthr/thread/thr_syscalls.c
index 10fbad4..e71bf4a 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)) =
OpenPOWER on IntegriCloud