mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 06:48:31 +00:00
Improve cancellations, randomness, and time
- Exhaustively document cancellation points - Rename SIGCANCEL to SIGTHR just like BSDs - Further improve POSIX thread cancellations - Ensure asynchronous cancellations work correctly - Elevate the quality of getrandom() and getentropy() - Make futexes cancel correctly on OpenBSD 6.x and 7.x - Add reboot.com and shutdown.com to examples directory - Remove underscore prefix from awesome timespec_*() APIs - Create assertions that help verify our cancellation points - Remove bad timespec APIs (cmp generalizes eq/ne/gt/gte/lt/lte)
This commit is contained in:
parent
0d7c265392
commit
3f0bcdc3ef
173 changed files with 1599 additions and 782 deletions
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/calls/cp.internal.h"
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/calls/struct/timespec.internal.h"
|
||||
#include "libc/errno.h"
|
||||
|
@ -42,11 +43,11 @@ static struct timespec *sem_timeout(struct timespec *memory,
|
|||
*memory = *abstime;
|
||||
return memory;
|
||||
} else {
|
||||
now = _timespec_real();
|
||||
if (_timespec_cmp(now, *abstime) > 0) {
|
||||
now = timespec_real();
|
||||
if (timespec_cmp(now, *abstime) > 0) {
|
||||
*memory = (struct timespec){0};
|
||||
} else {
|
||||
*memory = _timespec_sub(*abstime, now);
|
||||
*memory = timespec_sub(*abstime, now);
|
||||
}
|
||||
return memory;
|
||||
}
|
||||
|
@ -87,6 +88,7 @@ int sem_timedwait(sem_t *sem, const struct timespec *abstime) {
|
|||
}
|
||||
}
|
||||
|
||||
BEGIN_CANCELLATION_POINT;
|
||||
_unassert(atomic_fetch_add_explicit(&sem->sem_waiters, +1,
|
||||
memory_order_acq_rel) >= 0);
|
||||
pthread_cleanup_push(sem_timedwait_cleanup, sem);
|
||||
|
@ -102,7 +104,7 @@ int sem_timedwait(sem_t *sem, const struct timespec *abstime) {
|
|||
rc = 0;
|
||||
} else if (rc == -ETIMEDOUT) {
|
||||
_npassert(abstime);
|
||||
if (_timespec_cmp(*abstime, _timespec_real()) <= 0) {
|
||||
if (timespec_cmp(*abstime, timespec_real()) <= 0) {
|
||||
rc = etimedout();
|
||||
} else {
|
||||
rc = 0;
|
||||
|
@ -122,6 +124,7 @@ int sem_timedwait(sem_t *sem, const struct timespec *abstime) {
|
|||
memory_order_relaxed)));
|
||||
|
||||
pthread_cleanup_pop(1);
|
||||
END_CANCELLATION_POINT;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue