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 int ftrylockfile(FILE *f)
23 pthread_t self = __pthread_self();
26 if (f->lockcount == LONG_MAX)
31 if (f->lock < 0) f->lock = 0;
32 if (f->lock || a_cas(&f->lock, 0, tid))
36 f->next_locked = self->stdio_locks;
37 if (f->next_locked) f->next_locked->prev_locked = f;
38 self->stdio_locks = f;