Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: fusl/src/stdio/__lockfile.c

Issue 1714623002: [fusl] clang-format fusl (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: headers too Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #include "stdio_impl.h" 1 #include "stdio_impl.h"
2 #include "pthread_impl.h" 2 #include "pthread_impl.h"
3 3
4 int __lockfile(FILE *f) 4 int __lockfile(FILE* f) {
5 { 5 int owner, tid = __pthread_self()->tid;
6 » int owner, tid = __pthread_self()->tid; 6 if (f->lock == tid)
7 » if (f->lock == tid) 7 return 0;
8 » » return 0; 8 while ((owner = a_cas(&f->lock, 0, tid)))
9 » while ((owner = a_cas(&f->lock, 0, tid))) 9 __wait(&f->lock, &f->waiters, owner, 1);
10 » » __wait(&f->lock, &f->waiters, owner, 1); 10 return 1;
11 » return 1;
12 } 11 }
13 12
14 void __unlockfile(FILE *f) 13 void __unlockfile(FILE* f) {
15 { 14 a_store(&f->lock, 0);
16 » a_store(&f->lock, 0);
17 15
18 » /* The following read is technically invalid under situations 16 /* The following read is technically invalid under situations
19 » * of self-synchronized destruction. Another thread may have 17 * of self-synchronized destruction. Another thread may have
20 » * called fclose as soon as the above store has completed. 18 * called fclose as soon as the above store has completed.
21 » * Nonetheless, since FILE objects always live in memory 19 * Nonetheless, since FILE objects always live in memory
22 » * obtained by malloc from the heap, it's safe to assume 20 * obtained by malloc from the heap, it's safe to assume
23 » * the dereferences below will not fault. In the worst case, 21 * the dereferences below will not fault. In the worst case,
24 » * a spurious syscall will be made. If the implementation of 22 * a spurious syscall will be made. If the implementation of
25 » * malloc changes, this assumption needs revisiting. */ 23 * malloc changes, this assumption needs revisiting. */
26 24
27 » if (f->waiters) __wake(&f->lock, 1, 1); 25 if (f->waiters)
26 __wake(&f->lock, 1, 1);
28 } 27 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698