source: asp3_tinet_ecnl_arm/trunk/musl-1.1.18/src/stdio/ftrylockfile.c@ 352

Last change on this file since 352 was 352, checked in by coas-nagasima, 6 years ago

arm向けASP3版ECNLを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc;charset=UTF-8
File size: 908 bytes
Line 
1#include "stdio_impl.h"
2#include "pthread_impl.h"
3#include <limits.h>
4
5void __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
12void __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
21int 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}
Note: See TracBrowser for help on using the repository browser.