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

@ -20,23 +20,29 @@
#include "libc/calls/struct/sched_param.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/atomic.h"
#include "libc/sysv/errfuns.h"
#include "libc/thread/posixthread.internal.h"
errno_t _pthread_reschedule(struct PosixThread *pt) {
int rc, e = errno;
int e, rc, tid;
int policy = pt->attr.__schedpolicy;
struct sched_param param = {pt->attr.__schedparam};
if (IsNetbsd()) {
rc = sys_sched_setparam_netbsd(0, pt->tid, policy, &param);
} else if (IsLinux()) {
rc = sys_sched_setscheduler(pt->tid, policy, &param);
} else if (IsFreebsd()) {
rc = _pthread_setschedparam_freebsd(pt->tid, policy, &param);
} else {
rc = enosys();
if (!(rc = pthread_getunique_np((pthread_t)pt, &tid))) {
e = errno;
if (IsNetbsd()) {
rc = sys_sched_setparam_netbsd(0, tid, policy, &param);
} else if (IsLinux()) {
rc = sys_sched_setscheduler(tid, policy, &param);
} else if (IsFreebsd()) {
rc = _pthread_setschedparam_freebsd(tid, policy, &param);
} else {
rc = enosys();
}
if (rc == -1) {
rc = errno;
errno = e;
}
}
rc = rc != -1 ? 0 : errno;
errno = e;
return rc;
}