Make fixes and improvements

- clock_nanosleep() is now much faster on OpenBSD and NetBSD
- Thread joining is now much faster on NetBSD
- FreeBSD timestamps are now more accurate
- Thread spawning now goes faster on XNU
- Clean up the clone() code
This commit is contained in:
Justine Tunney 2022-11-08 10:09:47 -08:00
parent aee50b1327
commit b407327972
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
47 changed files with 645 additions and 306 deletions

View file

@ -22,6 +22,7 @@
#include "libc/calls/struct/timespec.h"
#include "libc/errno.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/sysv/consts/clock.h"
#include "libc/sysv/consts/itimer.h"
#include "libc/sysv/consts/sa.h"
@ -31,6 +32,7 @@
void OnAlrm(int sig) {
// do nothing
STRACE("OnAlrm()");
}
TEST(nanosleep, testFault) {
@ -54,7 +56,7 @@ TEST(nanosleep, testInterrupt_remIsUpdated) {
.sa_flags = SA_RESETHAND,
};
ASSERT_SYS(0, 0, sigaction(SIGALRM, &sa, 0));
struct itimerval it = {{0, 0}, {0, 10000}}; // 10ms singleshot
struct itimerval it = {{0, 0}, {0, 100000}}; // 100ms singleshot
ASSERT_SYS(0, 0, setitimer(ITIMER_REAL, &it, 0));
struct timespec ts = {500, 0};
ASSERT_SYS(EINTR, -1, nanosleep(&ts, &ts));
@ -75,7 +77,7 @@ TEST(clock_nanosleep, testInterrupt_remIsUpdated) {
.sa_flags = SA_RESETHAND,
};
ASSERT_SYS(0, 0, sigaction(SIGALRM, &sa, 0));
struct itimerval it = {{0, 0}, {0, 10000}}; // 10ms singleshot
struct itimerval it = {{0, 0}, {0, 100000}}; // 100ms singleshot
ASSERT_SYS(0, 0, setitimer(ITIMER_REAL, &it, 0));
struct timespec ts = {500, 0};
ASSERT_EQ(EINTR, clock_nanosleep(CLOCK_REALTIME, 0, &ts, &ts));

View file

@ -39,8 +39,8 @@ void *Worker(void *arg) {
TEST(tkill, test) {
if (IsWindows()) return; // TODO(jart): fix me
int i;
void *res;
int i, tid;
pthread_t t;
sigset_t ss, oldss;
sighandler_t oldsig;
@ -49,7 +49,8 @@ TEST(tkill, test) {
oldsig = signal(SIGUSR1, OnSig);
ASSERT_SYS(0, 0, sigprocmask(SIG_BLOCK, &ss, &oldss));
ASSERT_EQ(0, pthread_create(&t, 0, Worker, 0));
ASSERT_SYS(0, 0, tkill(pthread_getunique_np(t), SIGUSR1));
ASSERT_EQ(0, pthread_getunique_np(t, &tid));
ASSERT_SYS(0, 0, tkill(tid, SIGUSR1));
ASSERT_EQ(0, pthread_join(t, &res));
ASSERT_EQ(SIGUSR1, (intptr_t)res);
ASSERT_SYS(0, 0, sigprocmask(SIG_SETMASK, &oldss, 0));