OSDN Git Service

PR libobjc/30445
[pf3gnuchains/gcc-fork.git] / libobjc / thr-irix.c
1 /* GNU Objective C Runtime Thread Interface - SGI IRIX Implementation
2    Copyright (C) 1996, 1997, 2009 Free Software Foundation, Inc.
3    Contributed by Galen C. Hunt (gchunt@cs.rochester.edu)
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under the
8 terms of the GNU General Public License as published by the Free Software
9 Foundation; either version 3, or (at your option) any later 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 FITNESS
13 FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14 details.
15
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
19
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23 <http://www.gnu.org/licenses/>.  */
24
25
26 #include <stdlib.h>
27 #include <sys/types.h>
28 #include <sys/sysmp.h>
29 #include <sys/prctl.h>
30 #include <ulocks.h>
31 #include "objc/thr.h"
32 #include "objc/runtime.h"
33
34 /* Key structure for maintaining thread specific storage */
35 static void * __objc_shared_arena_handle = NULL;
36
37 /* Backend initialization functions */
38
39 /* Initialize the threads subsystem. */
40 int
41 __objc_init_thread_system(void)
42 {
43   /* Name of IRIX arena. */
44   char arena_name[64];
45
46   DEBUG_PRINTF("__objc_init_thread_system\n");
47
48   /* Construct a temporary name for arena. */
49   sprintf(arena_name, "/usr/tmp/objc_%05u", (unsigned)getpid());
50
51   /* Up to 256 threads.  Arena only for threads. */
52   usconfig(CONF_INITUSERS, 256);
53   usconfig(CONF_ARENATYPE, US_SHAREDONLY);
54
55   /* Initialize the arena */
56   if (!(__objc_shared_arena_handle = usinit(arena_name)))
57     /* Failed */
58     return -1;
59
60   return 0;
61 }
62
63 /* Close the threads subsystem. */
64 int
65 __objc_close_thread_system(void)
66 {
67   return 0;
68 }
69
70 /* Backend thread functions */
71
72 /* Create a new thread of execution. */
73 objc_thread_t
74 __objc_thread_detach(void (*func)(void *arg), void *arg)
75 {
76   objc_thread_t thread_id;
77   int sys_id;
78
79   if ((sys_id = sproc((void *)func, PR_SALL, arg)) >= 0)
80     thread_id = (objc_thread_t)sys_id;
81   else
82     thread_id = NULL;
83   
84   return thread_id;
85 }
86
87 /* Set the current thread's priority. */
88 int
89 __objc_thread_set_priority(int priority)
90 {
91   /* Not implemented yet */
92   return -1;
93 }
94
95 /* Return the current thread's priority. */
96 int
97 __objc_thread_get_priority(void)
98 {
99   /* Not implemented yet */
100   return OBJC_THREAD_INTERACTIVE_PRIORITY;
101 }
102
103 /* Yield our process time to another thread. */
104 void
105 __objc_thread_yield(void)
106 {
107   sginap(0);
108 }
109
110 /* Terminate the current thread. */
111 int
112 __objc_thread_exit(void)
113 {
114   /* IRIX only has exit. */
115   exit(__objc_thread_exit_status);
116
117   /* Failed if we reached here */
118   return -1;
119 }
120
121 /* Returns an integer value which uniquely describes a thread. */
122 objc_thread_t
123 __objc_thread_id(void)
124 {
125   /* Threads are processes. */
126   return (objc_thread_t)get_pid();
127 }
128
129 /* Sets the thread's local storage pointer. */
130 int
131 __objc_thread_set_data(void *value)
132 {
133   *((void **)&PRDA->usr_prda) = value;
134   return 0;
135 }
136
137 /* Returns the thread's local storage pointer. */
138 void *
139 __objc_thread_get_data(void)
140 {
141   return *((void **)&PRDA->usr_prda);
142 }
143
144 /* Backend mutex functions */
145
146 /* Allocate a mutex. */
147 int
148 __objc_mutex_allocate(objc_mutex_t mutex)
149 {
150   if (!( (ulock_t)(mutex->backend) = usnewlock(__objc_shared_arena_handle) ))
151     return -1;
152   else
153     return 0;
154 }
155
156 /* Deallocate a mutex. */
157 int
158 __objc_mutex_deallocate(objc_mutex_t mutex)
159 {
160   usfreelock((ulock_t)(mutex->backend), __objc_shared_arena_handle);
161   return 0;
162 }
163
164 /* Grab a lock on a mutex. */
165 int
166 __objc_mutex_lock(objc_mutex_t mutex)
167 {
168   if (ussetlock((ulock_t)(mutex->backend)) == 0)
169     return -1;
170   else
171     return 0;
172 }
173
174 /* Try to grab a lock on a mutex. */
175 int
176 __objc_mutex_trylock(objc_mutex_t mutex)
177 {
178   if (ustestlock((ulock_t)(mutex->backend)) == 0)
179     return -1;
180   else
181     return 0;
182 }
183
184 /* Unlock the mutex */
185 int
186 __objc_mutex_unlock(objc_mutex_t mutex)
187 {
188   usunsetlock((ulock_t)(mutex->backend));
189   return 0;
190 }
191
192 /* Backend condition mutex functions */
193
194 /* Allocate a condition. */
195 int
196 __objc_condition_allocate(objc_condition_t condition)
197 {
198   /* Unimplemented. */
199   return -1;
200 }
201
202 /* Deallocate a condition. */
203 int
204 __objc_condition_deallocate(objc_condition_t condition)
205 {
206   /* Unimplemented. */
207   return -1;
208 }
209
210 /* Wait on the condition */
211 int
212 __objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex)
213 {
214   /* Unimplemented. */
215   return -1;
216 }
217
218 /* Wake up all threads waiting on this condition. */
219 int
220 __objc_condition_broadcast(objc_condition_t condition)
221 {
222   /* Unimplemented. */
223   return -1;
224 }
225
226 /* Wake up one thread waiting on this condition. */
227 int
228 __objc_condition_signal(objc_condition_t condition)
229 {
230   /* Unimplemented. */
231   return -1;
232 }
233
234 /* End of File */