mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-03 01:38: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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue