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 void __register_locked_file(FILE *f, pthread_t self)
27 f->next_locked = self->stdio_locks;
28 if (f->next_locked) f->next_locked->prev_locked = f;
29 self->stdio_locks = f;
32 int ftrylockfile(FILE *f)
34 pthread_t self = __pthread_self();
37 if ((owner & ~MAYBE_WAITERS) == tid) {
38 if (f->lockcount == LONG_MAX)
43 if (owner < 0) f->lock = owner = 0;
44 if (owner || a_cas(&f->lock, 0, tid))
46 __register_locked_file(f, self);