X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstdio%2Fftrylockfile.c;h=0b0e44aaf4fb6d7da1922b44e80b0926870376d1;hb=aed707f679cce80afd929f0efaf080f1e8481330;hp=725b66e735aff23ed5e9c0a2335d677ace3374ce;hpb=5eb0d33ec0f08b123c5c10877d6258d05fa9453a;p=musl diff --git a/src/stdio/ftrylockfile.c b/src/stdio/ftrylockfile.c index 725b66e7..0b0e44aa 100644 --- a/src/stdio/ftrylockfile.c +++ b/src/stdio/ftrylockfile.c @@ -3,16 +3,15 @@ int ftrylockfile(FILE *f) { - libc.lockfile = __lockfile; - if (f->owner && f->owner == pthread_self()->tid) { + int tid = pthread_self()->tid; + if (f->lock == tid) { if (f->lockcount == INT_MAX) return -1; f->lockcount++; return 0; } - if (a_swap(&f->lock, 1)) + if (f->lock || a_cas(&f->lock, 0, tid)) return -1; - f->owner = pthread_self()->tid; f->lockcount = 1; return 0; }