source: vendor/gcc/3.2.2/libobjc/thr-irix.c

Last change on this file was 2, checked in by bird, 22 years ago

Initial revision

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