1 /* MIPS SDE threads compatibility routines for libgcc2 and libobjc. */
2 /* Compile this one with gcc. */
3 /* Copyright (C) 2006, 2007, 2008, 2009 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 3, 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 Under Section 7 of GPL version 3, you are granted additional
19 permissions described in the GCC Runtime Library Exception, version
20 3.1, as published by the Free Software Foundation.
22 You should have received a copy of the GNU General Public License and
23 a copy of the GCC Runtime Library Exception along with this program;
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 <http://www.gnu.org/licenses/>. */
27 #ifndef GCC_GTHR_MIPSSDE_H
28 #define GCC_GTHR_MIPSSDE_H
30 /* MIPS SDE threading API specific definitions.
31 Easy, since the interface is pretty much one-to-one. */
35 #include <sdethread.h>
42 typedef __sdethread_key_t __gthread_key_t
;
43 typedef __sdethread_once_t __gthread_once_t
;
44 typedef __sdethread_mutex_t __gthread_mutex_t
;
49 __sdethread_mutex_t actual
;
50 } __gthread_recursive_mutex_t
;
52 #define __GTHREAD_MUTEX_INIT __SDETHREAD_MUTEX_INITIALIZER("gthr")
53 #define __GTHREAD_ONCE_INIT __SDETHREAD_ONCE_INIT
55 __gthread_recursive_mutex_init_function(__gthread_recursive_mutex_t
*__mutex
);
56 #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function
58 #if SUPPORTS_WEAK && GTHREAD_USE_WEAK
59 # define __gthrw(name) \
60 static __typeof(name) __gthrw_ ## name __attribute__ ((__weakref__(#name)));
61 # define __gthrw_(name) __gthrw_ ## name
63 # define __gthrw(name)
64 # define __gthrw_(name) name
67 __gthrw(__sdethread_once
)
68 __gthrw(__sdethread_key_create
)
69 __gthrw(__sdethread_key_delete
)
70 __gthrw(__sdethread_getspecific
)
71 __gthrw(__sdethread_setspecific
)
73 __gthrw(__sdethread_self
)
75 __gthrw(__sdethread_mutex_lock
)
76 __gthrw(__sdethread_mutex_trylock
)
77 __gthrw(__sdethread_mutex_unlock
)
79 __gthrw(__sdethread_mutex_init
)
81 __gthrw(__sdethread_threading
)
83 #if SUPPORTS_WEAK && GTHREAD_USE_WEAK
86 __gthread_active_p (void)
88 return !!(void *)&__sdethread_threading
;
91 #else /* not SUPPORTS_WEAK */
94 __gthread_active_p (void)
99 #endif /* SUPPORTS_WEAK */
102 __gthread_once (__gthread_once_t
*__once
, void (*__func
) (void))
104 if (__gthread_active_p ())
105 return __gthrw_(__sdethread_once
) (__once
, __func
);
111 __gthread_key_create (__gthread_key_t
*__key
, void (*__dtor
) (void *))
113 return __gthrw_(__sdethread_key_create
) (__key
, __dtor
);
117 __gthread_key_delete (__gthread_key_t __key
)
119 return __gthrw_(__sdethread_key_delete
) (__key
);
123 __gthread_getspecific (__gthread_key_t __key
)
125 return __gthrw_(__sdethread_getspecific
) (__key
);
129 __gthread_setspecific (__gthread_key_t __key
, const void *__ptr
)
131 return __gthrw_(__sdethread_setspecific
) (__key
, __ptr
);
135 __gthread_mutex_destroy (__gthread_mutex_t
* UNUSED(__mutex
))
141 __gthread_mutex_lock (__gthread_mutex_t
*__mutex
)
143 if (__gthread_active_p ())
144 return __gthrw_(__sdethread_mutex_lock
) (__mutex
);
150 __gthread_mutex_trylock (__gthread_mutex_t
*__mutex
)
152 if (__gthread_active_p ())
153 return __gthrw_(__sdethread_mutex_trylock
) (__mutex
);
159 __gthread_mutex_unlock (__gthread_mutex_t
*__mutex
)
161 if (__gthread_active_p ())
162 return __gthrw_(__sdethread_mutex_unlock
) (__mutex
);
168 __gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t
*__mutex
)
171 __mutex
->owner
= __gthrw_(__sdethread_self
) ();
172 return __gthrw_(__sdethread_mutex_init
) (&__mutex
->actual
, NULL
);
176 __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t
*__mutex
)
178 if (__gthread_active_p ())
180 __sdethread_t __me
= __gthrw_(__sdethread_self
) ();
182 if (__mutex
->owner
!= __me
)
184 __gthrw_(__sdethread_mutex_lock
) (&__mutex
->actual
);
185 __mutex
->owner
= __me
;
194 __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t
*__mutex
)
196 if (__gthread_active_p ())
198 __sdethread_t __me
= __gthrw_(__sdethread_self
) ();
200 if (__mutex
->owner
!= __me
)
202 if (__gthrw_(__sdethread_mutex_trylock
) (&__mutex
->actual
))
204 __mutex
->owner
= __me
;
213 __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t
*__mutex
)
215 if (__gthread_active_p ())
217 if (--__mutex
->depth
== 0)
219 __mutex
->owner
= (__sdethread_t
) 0;
220 __gthrw_(__sdethread_mutex_unlock
) (&__mutex
->actual
);
230 #endif /* ! GCC_GTHR_MIPSSDE_H */