]>
git.proxmox.com Git - wasi-libc.git/blob - libc-top-half/musl/src/stdio/putc.h
7ebeeb6144298e3b60f6454a033a70499648bc29
1 #include "stdio_impl.h"
2 #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
3 #include "pthread_impl.h"
6 __attribute__((__noinline__
))
8 static int locking_putc(int c
, FILE *f
)
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);
18 static inline int do_putc(int c
, FILE *f
)
21 #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
22 if (l
< 0 || l
&& (l
& ~MAYBE_WAITERS
) == __pthread_self()->tid
)
23 return putc_unlocked(c
, f
);
24 return locking_putc(c
, f
);
26 // With no threads, locking is unnecessary.
27 return putc_unlocked(c
, f
);