mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 08:12:28 +00:00
Use re-entrant locks on stdio
This commit is contained in:
parent
4e9662cbc7
commit
1f229e4efc
78 changed files with 427 additions and 179 deletions
|
@ -28,15 +28,18 @@
|
|||
|
||||
_Alignas(64) static int rlock;
|
||||
|
||||
static privileged inline bool AcquireInterruptPollLock(void) {
|
||||
// return 0 on success, or tid of other owner
|
||||
static privileged inline int AcquireInterruptPollLock(void) {
|
||||
// any thread can poll for interrupts
|
||||
// but it's wasteful to have every single thread doing it
|
||||
int me, owner, tries;
|
||||
if (!__threaded) return true;
|
||||
me = gettid();
|
||||
owner = 0;
|
||||
if (_lockcmpxchgp(&rlock, &owner, me)) return true;
|
||||
return owner == me;
|
||||
int me, owner = 0;
|
||||
if (__threaded) {
|
||||
me = gettid();
|
||||
if (!_lockcmpxchgp(&rlock, &owner, me) && owner == me) {
|
||||
owner = 0;
|
||||
}
|
||||
}
|
||||
return owner;
|
||||
}
|
||||
|
||||
static textwindows inline void ReleaseInterruptPollLock(void) {
|
||||
|
@ -47,7 +50,7 @@ static textwindows inline void ReleaseInterruptPollLock(void) {
|
|||
textwindows bool _check_interrupts(bool restartable, struct Fd *fd) {
|
||||
bool res;
|
||||
if (__time_critical) return false;
|
||||
if (!AcquireInterruptPollLock()) return false;
|
||||
if (AcquireInterruptPollLock()) return false;
|
||||
if (weaken(_check_sigalrm)) weaken(_check_sigalrm)();
|
||||
if (weaken(_check_sigchld)) weaken(_check_sigchld)();
|
||||
if (fd && weaken(_check_sigwinch)) weaken(_check_sigwinch)(fd);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue