]> git.proxmox.com Git - wasi-libc.git/blame - libc-top-half/musl/src/stdio/putc.h
Format changes to musl code to fit musl's style.
[wasi-libc.git] / libc-top-half / musl / src / stdio / putc.h
CommitLineData
320054e8
DG
1#include "stdio_impl.h"
2#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
3#include "pthread_impl.h"
4
5#ifdef __GNUC__
6__attribute__((__noinline__))
7#endif
8static int locking_putc(int c, FILE *f)
9{
10 if (a_cas(&f->lock, 0, MAYBE_WAITERS-1)) __lockfile(f);
11 c = putc_unlocked(c, f);
12 if (a_swap(&f->lock, 0) & MAYBE_WAITERS)
13 __wake(&f->lock, 1, 1);
14 return c;
15}
16#endif
17
18static inline int do_putc(int c, FILE *f)
19{
320054e8 20#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
7ba6adfc 21 int l = f->lock;
320054e8
DG
22 if (l < 0 || l && (l & ~MAYBE_WAITERS) == __pthread_self()->tid)
23 return putc_unlocked(c, f);
24 return locking_putc(c, f);
25#else
ec9f1c39 26 // With no threads, locking is unnecessary.
320054e8
DG
27 return putc_unlocked(c, f);
28#endif
29}