]>
git.proxmox.com Git - wasi-libc.git/blob - libc-top-half/musl/src/stdio/ftrylockfile.c
1 #include "stdio_impl.h"
2 #include "pthread_impl.h"
5 void __do_orphaned_stdio_locks()
8 for (f
=__pthread_self()->stdio_locks
; f
; f
=f
->next_locked
)
9 a_store(&f
->lock
, 0x40000000);
12 void __unlist_locked_file(FILE *f
)
15 if (f
->next_locked
) f
->next_locked
->prev_locked
= f
->prev_locked
;
16 if (f
->prev_locked
) f
->prev_locked
->next_locked
= f
->next_locked
;
17 else __pthread_self()->stdio_locks
= f
->next_locked
;
21 void __register_locked_file(FILE *f
, pthread_t self
)
25 f
->next_locked
= self
->stdio_locks
;
26 if (f
->next_locked
) f
->next_locked
->prev_locked
= f
;
27 self
->stdio_locks
= f
;
30 int ftrylockfile(FILE *f
)
32 pthread_t self
= __pthread_self();
35 if ((owner
& ~MAYBE_WAITERS
) == tid
) {
36 if (f
->lockcount
== LONG_MAX
)
41 if (owner
< 0) f
->lock
= owner
= 0;
42 if (owner
|| a_cas(&f
->lock
, 0, tid
))
44 __register_locked_file(f
, self
);