Revert "Make spin locks go faster"

This reverts commit c8e25d811c.
This commit is contained in:
Justine Tunney 2024-07-25 22:24:32 -07:00
parent 0679cfeb41
commit 02e1cbcd00
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
16 changed files with 122 additions and 149 deletions

View file

@ -30,27 +30,15 @@
static int cpus;
static double load;
static pthread_spinlock_t lock;
static struct NtFileTime idle1, kern1, user1;
static pthread_mutex_t getloadavg_lock;
static void __getloadavg_lock(void) {
pthread_mutex_lock(&getloadavg_lock);
}
static void __getloadavg_unlock(void) {
pthread_mutex_unlock(&getloadavg_lock);
}
static void __getloadavg_wipe(void) {
pthread_mutex_init(&getloadavg_lock, 0);
}
textwindows int sys_getloadavg_nt(double *a, int n) {
int i, rc;
uint64_t elapsed, used;
struct NtFileTime idle, kern, user;
BLOCK_SIGNALS;
__getloadavg_lock();
pthread_spin_lock(&lock);
if (GetSystemTimes(&idle, &kern, &user)) {
elapsed = (FT(kern) - FT(kern1)) + (FT(user) - FT(user1));
if (elapsed) {
@ -66,7 +54,7 @@ textwindows int sys_getloadavg_nt(double *a, int n) {
} else {
rc = __winerr();
}
__getloadavg_unlock();
pthread_spin_unlock(&lock);
ALLOW_SIGNALS;
return rc;
}
@ -77,7 +65,5 @@ __attribute__((__constructor__(40))) static textstartup void ntinitload(void) {
cpus = __get_cpu_count() / 2;
cpus = MAX(1, cpus);
GetSystemTimes(&idle1, &kern1, &user1);
pthread_atfork(__getloadavg_lock, __getloadavg_unlock, __getloadavg_wipe);
__getloadavg_wipe();
}
}

View file

@ -51,7 +51,6 @@
#include "libc/sysv/consts/sicode.h"
#include "libc/sysv/consts/ss.h"
#include "libc/thread/posixthread.internal.h"
#include "libc/thread/thread.h"
#ifdef __x86_64__
/**
@ -65,20 +64,6 @@ struct SignalFrame {
ucontext_t ctx;
};
static pthread_mutex_t __sig_lock_obj;
static void __sig_wipe(void) {
pthread_mutex_init(&__sig_lock_obj, 0);
}
static void __sig_lock(void) {
pthread_mutex_lock(&__sig_lock_obj);
}
static void __sig_unlock(void) {
pthread_mutex_unlock(&__sig_lock_obj);
}
static textwindows bool __sig_ignored_by_default(int sig) {
return sig == SIGURG || //
sig == SIGCONT || //
@ -333,10 +318,11 @@ static textwindows int __sig_killer(struct PosixThread *pt, int sig, int sic) {
// take control of thread
// suspending the thread happens asynchronously
// however getting the context blocks until it's frozen
__sig_lock();
static pthread_spinlock_t killer_lock;
pthread_spin_lock(&killer_lock);
if (SuspendThread(th) == -1u) {
STRACE("SuspendThread failed w/ %d", GetLastError());
__sig_unlock();
pthread_spin_unlock(&killer_lock);
return ESRCH;
}
struct NtContext nc;
@ -344,10 +330,10 @@ static textwindows int __sig_killer(struct PosixThread *pt, int sig, int sic) {
if (!GetThreadContext(th, &nc)) {
STRACE("GetThreadContext failed w/ %d", GetLastError());
ResumeThread(th);
__sig_unlock();
pthread_spin_unlock(&killer_lock);
return ESRCH;
}
__sig_unlock();
pthread_spin_unlock(&killer_lock);
// we can't preempt threads that masked sig or are blocked
// we can't preempt threads that are running in win32 code
@ -626,8 +612,6 @@ __attribute__((__constructor__(10))) textstartup void __sig_init(void) {
return;
AddVectoredExceptionHandler(true, (void *)__sig_crash);
SetConsoleCtrlHandler((void *)__sig_console, true);
pthread_atfork(__sig_lock, __sig_unlock, __sig_wipe);
__sig_wipe();
}
#endif /* __x86_64__ */