author | Rich Felker <dalias@aerifal.cx> | 2018年10月18日 12:47:26 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2018年10月18日 13:09:33 -0400 |
commit | 9dd19122565c70bc6e0fff35724c91a61209a629 (patch) | |
tree | 272f42ab2c781e3663063779ab4a2e338fdd147a /src/stdio/getc.h | |
parent | 7eda27d025d6d52f855588590366c83d737eb727 (diff) | |
download | musl-9dd19122565c70bc6e0fff35724c91a61209a629.tar.gz |
-rw-r--r-- | src/stdio/getc.h | 10 |
diff --git a/src/stdio/getc.h b/src/stdio/getc.h index 0657ab6f..e24f9905 100644 --- a/src/stdio/getc.h +++ b/src/stdio/getc.h @@ -4,9 +4,9 @@ #ifdef __GNUC__ __attribute__((__noinline__)) #endif -static int locking_getc(FILE *f, int tid) +static int locking_getc(FILE *f) { - if (a_cas(&f->lock, 0, tid)) __lockfile(f); + if (a_cas(&f->lock, 0, MAYBE_WAITERS-1)) __lockfile(f); int c = getc_unlocked(f); if (a_swap(&f->lock, 0) & MAYBE_WAITERS) __wake(&f->lock, 1, 1); @@ -15,8 +15,8 @@ static int locking_getc(FILE *f, int tid) static inline int do_getc(FILE *f) { - int tid, l = f->lock; - if (l < 0 || (l & ~MAYBE_WAITERS) == (tid=__pthread_self()->tid)) + int l = f->lock; + if (l < 0 || l && (l & ~MAYBE_WAITERS) == __pthread_self()->tid) return getc_unlocked(f); - return locking_getc(f, tid); + return locking_getc(f); } |