X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=src%2Fstdio%2F__lockfile.c;h=4e0239e7e96399761effc4f60b8a151887454a07;hp=82f50b421efa1a0152351c63bcb1bba90ad8fb92;hb=eb0e8fa0b1960cff4bd65ebefc798f70273b0bc9;hpb=5eb0d33ec0f08b123c5c10877d6258d05fa9453a diff --git a/src/stdio/__lockfile.c b/src/stdio/__lockfile.c index 82f50b42..4e0239e7 100644 --- a/src/stdio/__lockfile.c +++ b/src/stdio/__lockfile.c @@ -3,17 +3,18 @@ void __lockfile(FILE *f) { - int spins; - if (f->owner < 0) return; - if (f->owner && f->owner == __pthread_self()->tid) { + int spins=100000; + int tid; + + if (f->lock < 0) return; + tid = __pthread_self()->tid; + if (f->lock == tid) { while (f->lockcount == INT_MAX); f->lockcount++; return; } - spins = 100000; - while (a_swap(&f->lock, 1)) + while (a_cas(&f->lock, 0, tid)) if (spins) spins--, a_spin(); - else syscall0(__NR_sched_yield); - f->owner = __pthread_self()->tid; + else __syscall(SYS_sched_yield); f->lockcount = 1; }