mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-03-03 07:29:23 +00:00
Make clock_nanosleep() cancel faster
This commit is contained in:
parent
0c89516ac5
commit
e4dea37b8e
2 changed files with 14 additions and 7 deletions
|
@ -20,9 +20,8 @@
|
|||
#include "libc/intrin/atomic.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/thread/posixthread.internal.h"
|
||||
#ifdef __x86_64__
|
||||
|
||||
textwindows int _check_cancel(void) {
|
||||
int _check_cancel(void) {
|
||||
if (_weaken(_pthread_cancel_ack) && //
|
||||
_pthread_self() && !(_pthread_self()->pt_flags & PT_NOCANCEL) &&
|
||||
atomic_load_explicit(&_pthread_self()->pt_canceled,
|
||||
|
@ -31,5 +30,3 @@ textwindows int _check_cancel(void) {
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* __x86_64__ */
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/calls/cp.internal.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/calls/struct/timespec.internal.h"
|
||||
#include "libc/dce.h"
|
||||
|
@ -27,6 +28,7 @@
|
|||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/runtime/clktck.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sysv/consts/clock.h"
|
||||
#include "libc/sysv/consts/timer.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
@ -108,9 +110,17 @@ static int cosmo_clock_nanosleep(int clock, int flags,
|
|||
}
|
||||
|
||||
// spin through final scheduling quantum
|
||||
do unassert(!clock_gettime(time_clock, &now));
|
||||
while (timespec_cmp(now, deadline) < 0);
|
||||
return 0;
|
||||
int rc = 0;
|
||||
ftrace_enabled(-1);
|
||||
do {
|
||||
if (_check_cancel()) {
|
||||
rc = -1;
|
||||
break;
|
||||
}
|
||||
unassert(!clock_gettime(time_clock, &now));
|
||||
} while (timespec_cmp(now, deadline) < 0);
|
||||
ftrace_enabled(+1);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue