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/ftrylockfile.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 #include <limits.h> 3 #include <limits.h>
4 4
5 void __do_orphaned_stdio_locks() 5 void __do_orphaned_stdio_locks() {
6 { 6 FILE* f;
7 » FILE *f; 7 for (f = __pthread_self()->stdio_locks; f; f = f->next_locked)
8 » for (f=__pthread_self()->stdio_locks; f; f=f->next_locked) 8 a_store(&f->lock, 0x40000000);
9 » » a_store(&f->lock, 0x40000000);
10 } 9 }
11 10
12 void __unlist_locked_file(FILE *f) 11 void __unlist_locked_file(FILE* f) {
13 { 12 if (f->lockcount) {
14 » if (f->lockcount) { 13 if (f->next_locked)
15 » » if (f->next_locked) f->next_locked->prev_locked = f->prev_locked ; 14 f->next_locked->prev_locked = f->prev_locked;
16 » » if (f->prev_locked) f->prev_locked->next_locked = f->next_locked ; 15 if (f->prev_locked)
17 » » else __pthread_self()->stdio_locks = f->next_locked; 16 f->prev_locked->next_locked = f->next_locked;
18 » } 17 else
18 __pthread_self()->stdio_locks = f->next_locked;
19 }
19 } 20 }
20 21
21 int ftrylockfile(FILE *f) 22 int ftrylockfile(FILE* f) {
22 { 23 pthread_t self = __pthread_self();
23 » pthread_t self = __pthread_self(); 24 int tid = self->tid;
24 » int tid = self->tid; 25 if (f->lock == tid) {
25 » if (f->lock == tid) { 26 if (f->lockcount == LONG_MAX)
26 » » if (f->lockcount == LONG_MAX) 27 return -1;
27 » » » return -1; 28 f->lockcount++;
28 » » f->lockcount++; 29 return 0;
29 » » return 0; 30 }
30 » } 31 if (f->lock < 0)
31 » if (f->lock < 0) f->lock = 0; 32 f->lock = 0;
32 » if (f->lock || a_cas(&f->lock, 0, tid)) 33 if (f->lock || a_cas(&f->lock, 0, tid))
33 » » return -1; 34 return -1;
34 » f->lockcount = 1; 35 f->lockcount = 1;
35 » f->prev_locked = 0; 36 f->prev_locked = 0;
36 » f->next_locked = self->stdio_locks; 37 f->next_locked = self->stdio_locks;
37 » if (f->next_locked) f->next_locked->prev_locked = f; 38 if (f->next_locked)
38 » self->stdio_locks = f; 39 f->next_locked->prev_locked = f;
39 » return 0; 40 self->stdio_locks = f;
41 return 0;
40 } 42 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698