1 /* MIPS SDE threads compatibility routines for libgcc2 and libobjc. */
2 /* Compile this one with gcc. */
3 /* Copyright (C) 2006, 2007 Free Software Foundation, Inc.
4 Contributed by Nigel Stephens <nigel@mips.com>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 /* As a special exception, if you link this library with other files,
24 some of which are compiled with GCC, to produce an executable,
25 this library does not by itself cause the resulting executable
26 to be covered by the GNU General Public License.
27 This exception does not however invalidate any other reasons why
28 the executable file might be covered by the GNU General Public License. */
30 #ifndef GCC_GTHR_MIPSSDE_H
31 #define GCC_GTHR_MIPSSDE_H
33 /* MIPS SDE threading API specific definitions.
34 Easy, since the interface is pretty much one-to-one. */
38 #include <sdethread.h>
45 typedef __sdethread_key_t __gthread_key_t
;
46 typedef __sdethread_once_t __gthread_once_t
;
47 typedef __sdethread_mutex_t __gthread_mutex_t
;
52 __sdethread_mutex_t actual
;
53 } __gthread_recursive_mutex_t
;
55 #define __GTHREAD_MUTEX_INIT __SDETHREAD_MUTEX_INITIALIZER("gthr")
56 #define __GTHREAD_ONCE_INIT __SDETHREAD_ONCE_INIT
58 __gthread_recursive_mutex_init_function(__gthread_recursive_mutex_t
*mutex
);
59 #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function
61 #if SUPPORTS_WEAK && GTHREAD_USE_WEAK
62 # define __gthrw(name) \
63 static __typeof(name) __gthrw_ ## name __attribute__ ((__weakref__(#name)));
64 # define __gthrw_(name) __gthrw_ ## name
66 # define __gthrw(name)
67 # define __gthrw_(name) name
70 __gthrw(__sdethread_once
)
71 __gthrw(__sdethread_key_create
)
72 __gthrw(__sdethread_key_delete
)
73 __gthrw(__sdethread_getspecific
)
74 __gthrw(__sdethread_setspecific
)
76 __gthrw(__sdethread_self
)
78 __gthrw(__sdethread_mutex_lock
)
79 __gthrw(__sdethread_mutex_trylock
)
80 __gthrw(__sdethread_mutex_unlock
)
82 __gthrw(__sdethread_mutex_init
)
84 __gthrw(__sdethread_threading
)
86 #if SUPPORTS_WEAK && GTHREAD_USE_WEAK
89 __gthread_active_p (void)
91 return !!(void *)&__sdethread_threading
;
94 #else /* not SUPPORTS_WEAK */
97 __gthread_active_p (void)
102 #endif /* SUPPORTS_WEAK */
105 __gthread_once (__gthread_once_t
*once
, void (*func
) (void))
107 if (__gthread_active_p ())
108 return __gthrw_(__sdethread_once
) (once
, func
);
114 __gthread_key_create (__gthread_key_t
*key
, void (*dtor
) (void *))
116 return __gthrw_(__sdethread_key_create
) (key
, dtor
);
120 __gthread_key_delete (__gthread_key_t key
)
122 return __gthrw_(__sdethread_key_delete
) (key
);
126 __gthread_getspecific (__gthread_key_t key
)
128 return __gthrw_(__sdethread_getspecific
) (key
);
132 __gthread_setspecific (__gthread_key_t key
, const void *ptr
)
134 return __gthrw_(__sdethread_setspecific
) (key
, ptr
);
138 __gthread_mutex_destroy (__gthread_mutex_t
* UNUSED(mutex
))
144 __gthread_mutex_lock (__gthread_mutex_t
*mutex
)
146 if (__gthread_active_p ())
147 return __gthrw_(__sdethread_mutex_lock
) (mutex
);
153 __gthread_mutex_trylock (__gthread_mutex_t
*mutex
)
155 if (__gthread_active_p ())
156 return __gthrw_(__sdethread_mutex_trylock
) (mutex
);
162 __gthread_mutex_unlock (__gthread_mutex_t
*mutex
)
164 if (__gthread_active_p ())
165 return __gthrw_(__sdethread_mutex_unlock
) (mutex
);
171 __gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t
*mutex
)
174 mutex
->owner
= __gthrw_(__sdethread_self
) ();
175 return __gthrw_(__sdethread_mutex_init
) (&mutex
->actual
, NULL
);
179 __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t
*mutex
)
181 if (__gthread_active_p ())
183 __sdethread_t me
= __gthrw_(__sdethread_self
) ();
185 if (mutex
->owner
!= me
)
187 __gthrw_(__sdethread_mutex_lock
) (&mutex
->actual
);
197 __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t
*mutex
)
199 if (__gthread_active_p ())
201 __sdethread_t me
= __gthrw_(__sdethread_self
) ();
203 if (mutex
->owner
!= me
)
205 if (__gthrw_(__sdethread_mutex_trylock
) (&mutex
->actual
))
216 __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t
*mutex
)
218 if (__gthread_active_p ())
220 if (--mutex
->depth
== 0)
222 mutex
->owner
= (__sdethread_t
) 0;
223 __gthrw_(__sdethread_mutex_unlock
) (&mutex
->actual
);
233 #endif /* ! GCC_GTHR_MIPSSDE_H */