mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-04 18:28:30 +00:00
parent
0679cfeb41
commit
02e1cbcd00
16 changed files with 122 additions and 149 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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__ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue