iconv: add aliases for GBK
[musl.git] / src / stdio / getc.h
blobe24f9905c1f8c1c360e1a51da7ec515a5a596ae3
1 #include "stdio_impl.h"
2 #include "pthread_impl.h"
4 #ifdef __GNUC__
5 __attribute__((__noinline__))
6 #endif
7 static int locking_getc(FILE *f)
9 if (a_cas(&f->lock, 0, MAYBE_WAITERS-1)) __lockfile(f);
10 int c = getc_unlocked(f);
11 if (a_swap(&f->lock, 0) & MAYBE_WAITERS)
12 __wake(&f->lock, 1, 1);
13 return c;
16 static inline int do_getc(FILE *f)
18 int l = f->lock;
19 if (l < 0 || l && (l & ~MAYBE_WAITERS) == __pthread_self()->tid)
20 return getc_unlocked(f);
21 return locking_getc(f);