#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);
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);
}
#ifdef __GNUC__
__attribute__((__noinline__))
#endif
-static int locking_putc(int c, FILE *f, int tid)
+static int locking_putc(int c, FILE *f)
{
- if (a_cas(&f->lock, 0, tid)) __lockfile(f);
+ if (a_cas(&f->lock, 0, MAYBE_WAITERS-1)) __lockfile(f);
c = putc_unlocked(c, f);
if (a_swap(&f->lock, 0) & MAYBE_WAITERS)
__wake(&f->lock, 1, 1);
static inline int do_putc(int c, 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 putc_unlocked(c, f);
- return locking_putc(c, f, tid);
+ return locking_putc(c, f);
}