annotate libgcc/config/vxlib.c @ 120:f93fa5091070

fix conv1.c
author mir3636
date Thu, 08 Mar 2018 14:53:42 +0900
parents 04ced10e8804
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Copyright (C) 2002-2017 Free Software Foundation, Inc.
kono
parents:
diff changeset
2 Contributed by Zack Weinberg <zack@codesourcery.com>
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of GCC.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
7 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
8 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
9 version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
14 for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
17 permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
18 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
21 a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
23 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 /* Threads compatibility routines for libgcc2 for VxWorks.
kono
parents:
diff changeset
26 These are out-of-line routines called from gthr-vxworks.h. */
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 #include "tconfig.h"
kono
parents:
diff changeset
29 #include "tsystem.h"
kono
parents:
diff changeset
30 #include "gthr.h"
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 #if defined(__GTHREADS)
kono
parents:
diff changeset
33 #include <vxWorks.h>
kono
parents:
diff changeset
34 #ifndef __RTP__
kono
parents:
diff changeset
35 #include <vxLib.h>
kono
parents:
diff changeset
36 #endif
kono
parents:
diff changeset
37 #include <taskLib.h>
kono
parents:
diff changeset
38 #ifndef __RTP__
kono
parents:
diff changeset
39 #include <taskHookLib.h>
kono
parents:
diff changeset
40 #else
kono
parents:
diff changeset
41 # include <errno.h>
kono
parents:
diff changeset
42 #endif
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 /* Init-once operation.
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 This would be a clone of the implementation from gthr-solaris.h,
kono
parents:
diff changeset
47 except that we have a bootstrap problem - the whole point of this
kono
parents:
diff changeset
48 exercise is to prevent double initialization, but if two threads
kono
parents:
diff changeset
49 are racing with each other, once->mutex is liable to be initialized
kono
parents:
diff changeset
50 by both. Then each thread will lock its own mutex, and proceed to
kono
parents:
diff changeset
51 call the initialization routine.
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 So instead we use a bare atomic primitive (vxTas()) to handle
kono
parents:
diff changeset
54 mutual exclusion. Threads losing the race then busy-wait, calling
kono
parents:
diff changeset
55 taskDelay() to yield the processor, until the initialization is
kono
parents:
diff changeset
56 completed. Inefficient, but reliable. */
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 int
kono
parents:
diff changeset
59 __gthread_once (__gthread_once_t *guard, void (*func)(void))
kono
parents:
diff changeset
60 {
kono
parents:
diff changeset
61 if (guard->done)
kono
parents:
diff changeset
62 return 0;
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 #ifdef __RTP__
kono
parents:
diff changeset
65 __gthread_lock_library ();
kono
parents:
diff changeset
66 #else
kono
parents:
diff changeset
67 while (!vxTas ((void *)&guard->busy))
kono
parents:
diff changeset
68 {
kono
parents:
diff changeset
69 #ifdef __PPC__
kono
parents:
diff changeset
70 /* This can happen on powerpc, which is using all 32 bits
kono
parents:
diff changeset
71 of the gthread_once_t structure. */
kono
parents:
diff changeset
72 if (guard->done)
kono
parents:
diff changeset
73 return 0;
kono
parents:
diff changeset
74 #endif
kono
parents:
diff changeset
75 taskDelay (1);
kono
parents:
diff changeset
76 }
kono
parents:
diff changeset
77 #endif
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 /* Only one thread at a time gets here. Check ->done again, then
kono
parents:
diff changeset
80 go ahead and call func() if no one has done it yet. */
kono
parents:
diff changeset
81 if (!guard->done)
kono
parents:
diff changeset
82 {
kono
parents:
diff changeset
83 func ();
kono
parents:
diff changeset
84 guard->done = 1;
kono
parents:
diff changeset
85 }
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 #ifdef __RTP__
kono
parents:
diff changeset
88 __gthread_unlock_library ();
kono
parents:
diff changeset
89 #else
kono
parents:
diff changeset
90 guard->busy = 0;
kono
parents:
diff changeset
91 #endif
kono
parents:
diff changeset
92 return 0;
kono
parents:
diff changeset
93 }
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 #endif /* __GTHREADS */