1 #include "stdio_impl.h"
2 #include "pthread_impl.h"
5 __attribute__((__noinline__
))
7 static int locking_putc(int c
, FILE *f
)
9 if (a_cas(&f
->lock
, 0, MAYBE_WAITERS
-1)) __lockfile(f
);
10 c
= putc_unlocked(c
, f
);
11 if (a_swap(&f
->lock
, 0) & MAYBE_WAITERS
)
12 __wake(&f
->lock
, 1, 1);
16 static inline int do_putc(int c
, FILE *f
)
19 if (l
< 0 || l
&& (l
& ~MAYBE_WAITERS
) == __pthread_self()->tid
)
20 return putc_unlocked(c
, f
);
21 return locking_putc(c
, f
);