OSDN Git Service

* doc/extend.texi (MIPS DSP Built-in Functions): Document the DSP
[pf3gnuchains/gcc-fork.git] / gcc / config / vxlib.c
1 /* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
2    Contributed by Zack Weinberg <zack@codesourcery.com>
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING.  If not, write to the Free
18 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301, USA.  */
20
21 /* As a special exception, if you link this library with other files,
22    some of which are compiled with GCC, to produce an executable,
23    this library does not by itself cause the resulting executable
24    to be covered by the GNU General Public License.
25    This exception does not however invalidate any other reasons why
26    the executable file might be covered by the GNU General Public License.  */
27
28 /* Threads compatibility routines for libgcc2 for VxWorks.
29    These are out-of-line routines called from gthr-vxworks.h.  */
30
31 #include "tconfig.h"
32 #include "tsystem.h"
33 #include "gthr.h"
34
35 #if defined(__GTHREADS)
36 #include <vxWorks.h>
37 #ifndef __RTP__
38 #include <vxLib.h>
39 #endif
40 #include <taskLib.h>
41 #ifndef __RTP__
42 #include <taskHookLib.h>
43 #else
44 # include <errno.h>
45 #endif
46
47 /* Init-once operation.
48
49    This would be a clone of the implementation from gthr-solaris.h,
50    except that we have a bootstrap problem - the whole point of this
51    exercise is to prevent double initialization, but if two threads
52    are racing with each other, once->mutex is liable to be initialized
53    by both.  Then each thread will lock its own mutex, and proceed to
54    call the initialization routine.
55
56    So instead we use a bare atomic primitive (vxTas()) to handle
57    mutual exclusion.  Threads losing the race then busy-wait, calling
58    taskDelay() to yield the processor, until the initialization is
59    completed.  Inefficient, but reliable.  */
60
61 int
62 __gthread_once (__gthread_once_t *guard, void (*func)(void))
63 {
64   if (guard->done)
65     return 0;
66
67 #ifdef __RTP__
68   __gthread_lock_library ();
69 #else
70   while (!vxTas ((void *)&guard->busy))
71     taskDelay (1);
72 #endif
73
74   /* Only one thread at a time gets here.  Check ->done again, then
75      go ahead and call func() if no one has done it yet.  */
76   if (!guard->done)
77     {
78       func ();
79       guard->done = 1;
80     }
81
82 #ifdef __RTP__
83   __gthread_unlock_library ();
84 #else
85   guard->busy = 0;
86 #endif
87   return 0;
88 }
89
90 #endif /* __GTHREADS */