source: asp3_tinet_ecnl_arm/trunk/musl-1.1.18/src/stdio/__lockfile.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: 830 bytes
Line 
1#include "stdio_impl.h"
2#include "pthread_impl.h"
3
4int __lockfile(FILE *f)
5{
6 int owner, tid = __pthread_self()->tid;
7 if (f->lock == tid)
8 return 0;
9 while ((owner = a_cas(&f->lock, 0, tid)))
10 __wait(&f->lock, &f->waiters, owner, 1);
11 return 1;
12}
13
14void __unlockfile(FILE *f)
15{
16 a_store(&f->lock, 0);
17
18 /* The following read is technically invalid under situations
19 * of self-synchronized destruction. Another thread may have
20 * called fclose as soon as the above store has completed.
21 * Nonetheless, since FILE objects always live in memory
22 * obtained by malloc from the heap, it's safe to assume
23 * the dereferences below will not fault. In the worst case,
24 * a spurious syscall will be made. If the implementation of
25 * malloc changes, this assumption needs revisiting. */
26
27 if (f->waiters) __wake(&f->lock, 1, 1);
28}
Note: See TracBrowser for help on using the repository browser.