1 #include "stdio_impl.h"
2 #include "pthread_impl.h"
5 #define MAYBE_WAITERS 0x40000000
7 void __do_orphaned_stdio_locks()
10 for (f=__pthread_self()->stdio_locks; f; f=f->next_locked)
11 a_store(&f->lock, 0x40000000);
14 void __unlist_locked_file(FILE *f)
17 if (f->next_locked) f->next_locked->prev_locked = f->prev_locked;
18 if (f->prev_locked) f->prev_locked->next_locked = f->next_locked;
19 else __pthread_self()->stdio_locks = f->next_locked;
23 int ftrylockfile(FILE *f)
25 pthread_t self = __pthread_self();
28 if ((owner & ~MAYBE_WAITERS) == tid) {
29 if (f->lockcount == LONG_MAX)
34 if (owner < 0) f->lock = owner = 0;
35 if (owner || a_cas(&f->lock, 0, tid))
39 f->next_locked = self->stdio_locks;
40 if (f->next_locked) f->next_locked->prev_locked = f;
41 self->stdio_locks = f;