mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 08:12:28 +00:00
Make locks more reliable
This change switches most of the core locks to be re-entrant, in order to reduce the chance of deadlocking code that does, clever things with asynchronous signal handlers. This change implements it it in pthreads so we're one step closer to having a standardized threading primitives
This commit is contained in:
parent
5ea618f0af
commit
c260345e06
35 changed files with 369 additions and 258 deletions
|
@ -16,9 +16,6 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/intrin/lockcmpxchgp.h"
|
||||
#include "libc/nexgen32e/threaded.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
/**
|
||||
|
@ -27,15 +24,5 @@
|
|||
* @return 0 on success, or non-zero if another thread owns the lock
|
||||
*/
|
||||
int ftrylockfile(FILE *f) {
|
||||
int me, owner = 0;
|
||||
if (__threaded) {
|
||||
me = gettid();
|
||||
if (!_lockcmpxchgp(&f->lock, &owner, me) && owner == me) {
|
||||
owner = 0;
|
||||
}
|
||||
}
|
||||
if (!owner) {
|
||||
++f->reent;
|
||||
}
|
||||
return owner;
|
||||
return pthread_mutex_trylock(&f->lock);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue