aboutsummaryrefslogtreecommitdiff
path: root/lib/libthr
diff options
context:
space:
mode:
authorEric van Gyzen <vangyzen@FreeBSD.org>2017-03-19 00:51:12 +0000
committerEric van Gyzen <vangyzen@FreeBSD.org>2017-03-19 00:51:12 +0000
commit3f8455b0905a05552b1155e09165787e1d098060 (patch)
tree7e464dbfe7b8012fa2a68d9d0a7b2d3a07b11df3 /lib/libthr
parenta776eeafdcaae027734542d69612d35971b55c1c (diff)
downloadsrc-3f8455b0905a05552b1155e09165787e1d098060.tar.gz
src-3f8455b0905a05552b1155e09165787e1d098060.zip
Add clock_nanosleep()
Add a clock_nanosleep() syscall, as specified by POSIX. Make nanosleep() a wrapper around it. Attach the clock_nanosleep test from NetBSD. Adjust it for the FreeBSD behavior of updating rmtp only when interrupted by a signal. I believe this to be POSIX-compliant, since POSIX mentions the rmtp parameter only in the paragraph about EINTR. This is also what Linux does. (NetBSD updates rmtp unconditionally.) Copy the whole nanosleep.2 man page from NetBSD because it is complete and closely resembles the POSIX description. Edit, polish, and reword it a bit, being sure to keep any relevant text from the FreeBSD page. Reviewed by: kib, ngie, jilles MFC after: 3 weeks Relnotes: yes Sponsored by: Dell EMC Differential Revision: https://reviews.freebsd.org/D10020
Notes
Notes: svn path=/head/; revision=315526
Diffstat (limited to 'lib/libthr')
-rw-r--r--lib/libthr/thread/thr_private.h2
-rw-r--r--lib/libthr/thread/thr_syscalls.c17
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h
index 9bea65f38491..56ecdb441310 100644
--- a/lib/libthr/thread/thr_private.h
+++ b/lib/libthr/thread/thr_private.h
@@ -865,6 +865,8 @@ int __sys_sigwaitinfo(const sigset_t *set, siginfo_t *info);
/* #include <time.h> */
#ifdef _TIME_H_
+int __sys_clock_nanosleep(clockid_t, int, const struct timespec *,
+ struct timespec *);
int __sys_nanosleep(const struct timespec *, struct timespec *);
#endif
diff --git a/lib/libthr/thread/thr_syscalls.c b/lib/libthr/thread/thr_syscalls.c
index 362826ca2f91..92d0c99d2831 100644
--- a/lib/libthr/thread/thr_syscalls.c
+++ b/lib/libthr/thread/thr_syscalls.c
@@ -260,6 +260,22 @@ __thr_msync(void *addr, size_t len, int flags)
}
static int
+__thr_clock_nanosleep(clockid_t clock_id, int flags,
+ const struct timespec *time_to_sleep, struct timespec *time_remaining)
+{
+ struct pthread *curthread;
+ int ret;
+
+ curthread = _get_curthread();
+ _thr_cancel_enter(curthread);
+ ret = __sys_clock_nanosleep(clock_id, flags, time_to_sleep,
+ time_remaining);
+ _thr_cancel_leave(curthread, 1);
+
+ return (ret);
+}
+
+static int
__thr_nanosleep(const struct timespec *time_to_sleep,
struct timespec *time_remaining)
{
@@ -668,6 +684,7 @@ __thr_interpose_libc(void)
SLOT(ppoll);
SLOT(map_stacks_exec);
SLOT(fdatasync);
+ SLOT(clock_nanosleep);
#undef SLOT
*(__libc_interposing_slot(
INTERPOS__pthread_mutex_init_calloc_cb)) =