mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-26 14:28:30 +00:00
Improve Windows sleep accuracy from 15ms to 15µs
This commit is contained in:
parent
b40140e6c5
commit
b490e23d63
16 changed files with 189 additions and 67 deletions
|
@ -18,21 +18,20 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/sigset.internal.h"
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/calls/syscall_support-nt.internal.h"
|
||||
#ifdef __x86_64__
|
||||
|
||||
textwindows int sys_pause_nt(void) {
|
||||
int rc;
|
||||
// we don't strictly need to block signals, but it reduces signal
|
||||
// delivery latency, by preventing other threads from delivering a
|
||||
// signal asynchronously. it takes about ~5us to deliver a signal
|
||||
// using SetEvent() whereas it takes ~30us to use SuspendThread(),
|
||||
// GetThreadContext(), SetThreadContext(), and ResumeThread().
|
||||
BLOCK_SIGNALS;
|
||||
while (!(rc = _park_norestart(-1u, 0)))
|
||||
donothing;
|
||||
_park_norestart(timespec_max, 0);
|
||||
ALLOW_SIGNALS;
|
||||
return rc;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif /* __x86_64__ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue