blob: 84a5fc1da987248aa3f4a53e077e0fbe6a0895fb [file] [log] [blame]
Ben Elliston88e17b51998-09-21 01:22:07 +00001/* GNU Objective C Runtime Thread Interface - SGI IRIX Implementation
Jakub Jelinek748086b2009-04-09 17:00:19 +02002 Copyright (C) 1996, 1997, 2009 Free Software Foundation, Inc.
Ben Elliston88e17b51998-09-21 01:22:07 +00003 Contributed by Galen C. Hunt (gchunt@cs.rochester.edu)
4
Nathanael Nerode38709ca2003-05-23 20:25:39 +00005This file is part of GCC.
Ben Elliston88e17b51998-09-21 01:22:07 +00006
Nathanael Nerode38709ca2003-05-23 20:25:39 +00007GCC is free software; you can redistribute it and/or modify it under the
Ben Elliston88e17b51998-09-21 01:22:07 +00008terms of the GNU General Public License as published by the Free Software
Jakub Jelinek748086b2009-04-09 17:00:19 +02009Foundation; either version 3, or (at your option) any later version.
Ben Elliston88e17b51998-09-21 01:22:07 +000010
Nathanael Nerode38709ca2003-05-23 20:25:39 +000011GCC is distributed in the hope that it will be useful, but WITHOUT ANY
Ben Elliston88e17b51998-09-21 01:22:07 +000012WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14details.
15
Jakub Jelinek748086b2009-04-09 17:00:19 +020016Under Section 7 of GPL version 3, you are granted additional
17permissions described in the GCC Runtime Library Exception, version
183.1, as published by the Free Software Foundation.
Ben Elliston88e17b51998-09-21 01:22:07 +000019
Jakub Jelinek748086b2009-04-09 17:00:19 +020020You should have received a copy of the GNU General Public License and
21a copy of the GCC Runtime Library Exception along with this program;
22see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23<http://www.gnu.org/licenses/>. */
24
Ben Elliston88e17b51998-09-21 01:22:07 +000025
26#include <stdlib.h>
27#include <sys/types.h>
28#include <sys/sysmp.h>
29#include <sys/prctl.h>
30#include <ulocks.h>
David Ayers348a3442005-06-07 23:04:19 +020031#include "objc/thr.h"
32#include "objc/runtime.h"
Ben Elliston88e17b51998-09-21 01:22:07 +000033
34/* Key structure for maintaining thread specific storage */
35static void * __objc_shared_arena_handle = NULL;
36
37/* Backend initialization functions */
38
39/* Initialize the threads subsystem. */
40int
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. */
64int
65__objc_close_thread_system(void)
66{
67 return 0;
68}
69
70/* Backend thread functions */
71
72/* Create a new thread of execution. */
73objc_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. */
88int
89__objc_thread_set_priority(int priority)
90{
91 /* Not implemented yet */
92 return -1;
93}
94
95/* Return the current thread's priority. */
96int
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. */
104void
105__objc_thread_yield(void)
106{
107 sginap(0);
108}
109
110/* Terminate the current thread. */
111int
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. */
122objc_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. */
130int
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. */
138void *
139__objc_thread_get_data(void)
140{
141 return *((void **)&PRDA->usr_prda);
142}
143
144/* Backend mutex functions */
145
146/* Allocate a mutex. */
147int
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. */
157int
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. */
165int
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. */
175int
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 */
185int
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. */
195int
196__objc_condition_allocate(objc_condition_t condition)
197{
198 /* Unimplemented. */
199 return -1;
200}
201
202/* Deallocate a condition. */
203int
204__objc_condition_deallocate(objc_condition_t condition)
205{
206 /* Unimplemented. */
207 return -1;
208}
209
210/* Wait on the condition */
211int
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. */
219int
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. */
227int
228__objc_condition_signal(objc_condition_t condition)
229{
230 /* Unimplemented. */
231 return -1;
232}
233
234/* End of File */