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
|
@ -16,13 +16,23 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/spinlock.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/intrin/lockcmpxchgp.h"
|
||||
#include "libc/nexgen32e/threaded.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
/**
|
||||
* Tries to acquire stdio object lock.
|
||||
* @return 0 for success or non-zero if someone else has the lock
|
||||
* Tries to acquire reentrant stdio object lock.
|
||||
*
|
||||
* @return 0 on success, or non-zero if another thread owns the lock
|
||||
*/
|
||||
int ftrylockfile(FILE *f) {
|
||||
return _trylock(&f->lock);
|
||||
int me, owner = 0;
|
||||
if (__threaded) {
|
||||
me = gettid();
|
||||
if (!_lockcmpxchgp(&f->lock, &owner, me) && owner == me) {
|
||||
owner = 0;
|
||||
}
|
||||
}
|
||||
return owner;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue