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

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

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « fusl/src/stdio/ftell.c ('k') | fusl/src/stdio/funlockfile.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #include "stdio_impl.h"
2 #include "pthread_impl.h"
3 #include <limits.h>
4
5 void __do_orphaned_stdio_locks()
6 {
7 FILE *f;
8 for (f=__pthread_self()->stdio_locks; f; f=f->next_locked)
9 a_store(&f->lock, 0x40000000);
10 }
11
12 void __unlist_locked_file(FILE *f)
13 {
14 if (f->lockcount) {
15 if (f->next_locked) f->next_locked->prev_locked = f->prev_locked ;
16 if (f->prev_locked) f->prev_locked->next_locked = f->next_locked ;
17 else __pthread_self()->stdio_locks = f->next_locked;
18 }
19 }
20
21 int ftrylockfile(FILE *f)
22 {
23 pthread_t self = __pthread_self();
24 int tid = self->tid;
25 if (f->lock == tid) {
26 if (f->lockcount == LONG_MAX)
27 return -1;
28 f->lockcount++;
29 return 0;
30 }
31 if (f->lock < 0) f->lock = 0;
32 if (f->lock || a_cas(&f->lock, 0, tid))
33 return -1;
34 f->lockcount = 1;
35 f->prev_locked = 0;
36 f->next_locked = self->stdio_locks;
37 if (f->next_locked) f->next_locked->prev_locked = f;
38 self->stdio_locks = f;
39 return 0;
40 }
OLDNEW
« no previous file with comments | « fusl/src/stdio/ftell.c ('k') | fusl/src/stdio/funlockfile.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698