]>
git.proxmox.com Git - wasi-libc.git/blob - libc-top-half/musl/src/stdio/getc.h
c61dd64230df5fee6a2f70890106622030428874
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_getc(FILE *f
)
10 if (a_cas(&f
->lock
, 0, MAYBE_WAITERS
-1)) __lockfile(f
);
11 int c
= getc_unlocked(f
);
12 if (a_swap(&f
->lock
, 0) & MAYBE_WAITERS
)
13 __wake(&f
->lock
, 1, 1);
18 static inline int do_getc(FILE *f
)
20 #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
22 if (l
< 0 || l
&& (l
& ~MAYBE_WAITERS
) == __pthread_self()->tid
)
23 return getc_unlocked(f
);
24 return locking_getc(f
);
26 // With no threads, locking is unnecessary.
27 return getc_unlocked(f
);