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)
5 This file is part of GCC.
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 2, or (at your option) any later version.
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
16 You should have received a copy of the GNU General Public License along with
17 GCC; see the file COPYING. If not, write to the Free Software
18 Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
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. */
28 #include <sys/types.h>
29 #include <sys/sysmp.h>
30 #include <sys/prctl.h>
33 #include "objc/runtime.h"
35 /* Key structure for maintaining thread specific storage */
36 static void * __objc_shared_arena_handle
= NULL
;
38 /* Backend initialization functions */
40 /* Initialize the threads subsystem. */
42 __objc_init_thread_system(void)
44 /* Name of IRIX arena. */
47 DEBUG_PRINTF("__objc_init_thread_system\n");
49 /* Construct a temporary name for arena. */
50 sprintf(arena_name
, "/usr/tmp/objc_%05u", (unsigned)getpid());
52 /* Up to 256 threads. Arena only for threads. */
53 usconfig(CONF_INITUSERS
, 256);
54 usconfig(CONF_ARENATYPE
, US_SHAREDONLY
);
56 /* Initialize the arena */
57 if (!(__objc_shared_arena_handle
= usinit(arena_name
)))
64 /* Close the threads subsystem. */
66 __objc_close_thread_system(void)
71 /* Backend thread functions */
73 /* Create a new thread of execution. */
75 __objc_thread_detach(void (*func
)(void *arg
), void *arg
)
77 objc_thread_t thread_id
;
80 if ((sys_id
= sproc((void *)func
, PR_SALL
, arg
)) >= 0)
81 thread_id
= (objc_thread_t
)sys_id
;
88 /* Set the current thread's priority. */
90 __objc_thread_set_priority(int priority
)
92 /* Not implemented yet */
96 /* Return the current thread's priority. */
98 __objc_thread_get_priority(void)
100 /* Not implemented yet */
101 return OBJC_THREAD_INTERACTIVE_PRIORITY
;
104 /* Yield our process time to another thread. */
106 __objc_thread_yield(void)
111 /* Terminate the current thread. */
113 __objc_thread_exit(void)
115 /* IRIX only has exit. */
116 exit(__objc_thread_exit_status
);
118 /* Failed if we reached here */
122 /* Returns an integer value which uniquely describes a thread. */
124 __objc_thread_id(void)
126 /* Threads are processes. */
127 return (objc_thread_t
)get_pid();
130 /* Sets the thread's local storage pointer. */
132 __objc_thread_set_data(void *value
)
134 *((void **)&PRDA
->usr_prda
) = value
;
138 /* Returns the thread's local storage pointer. */
140 __objc_thread_get_data(void)
142 return *((void **)&PRDA
->usr_prda
);
145 /* Backend mutex functions */
147 /* Allocate a mutex. */
149 __objc_mutex_allocate(objc_mutex_t mutex
)
151 if (!( (ulock_t
)(mutex
->backend
) = usnewlock(__objc_shared_arena_handle
) ))
157 /* Deallocate a mutex. */
159 __objc_mutex_deallocate(objc_mutex_t mutex
)
161 usfreelock((ulock_t
)(mutex
->backend
), __objc_shared_arena_handle
);
165 /* Grab a lock on a mutex. */
167 __objc_mutex_lock(objc_mutex_t mutex
)
169 if (ussetlock((ulock_t
)(mutex
->backend
)) == 0)
175 /* Try to grab a lock on a mutex. */
177 __objc_mutex_trylock(objc_mutex_t mutex
)
179 if (ustestlock((ulock_t
)(mutex
->backend
)) == 0)
185 /* Unlock the mutex */
187 __objc_mutex_unlock(objc_mutex_t mutex
)
189 usunsetlock((ulock_t
)(mutex
->backend
));
193 /* Backend condition mutex functions */
195 /* Allocate a condition. */
197 __objc_condition_allocate(objc_condition_t condition
)
203 /* Deallocate a condition. */
205 __objc_condition_deallocate(objc_condition_t condition
)
211 /* Wait on the condition */
213 __objc_condition_wait(objc_condition_t condition
, objc_mutex_t mutex
)
219 /* Wake up all threads waiting on this condition. */
221 __objc_condition_broadcast(objc_condition_t condition
)
227 /* Wake up one thread waiting on this condition. */
229 __objc_condition_signal(objc_condition_t condition
)