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)
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 3, 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 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.
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/>. */
27 #include <sys/types.h>
28 #include <sys/sysmp.h>
29 #include <sys/prctl.h>
32 #include "objc/runtime.h"
34 /* Key structure for maintaining thread specific storage */
35 static void * __objc_shared_arena_handle
= NULL
;
37 /* Backend initialization functions */
39 /* Initialize the threads subsystem. */
41 __objc_init_thread_system(void)
43 /* Name of IRIX arena. */
46 DEBUG_PRINTF("__objc_init_thread_system\n");
48 /* Construct a temporary name for arena. */
49 sprintf(arena_name
, "/usr/tmp/objc_%05u", (unsigned)getpid());
51 /* Up to 256 threads. Arena only for threads. */
52 usconfig(CONF_INITUSERS
, 256);
53 usconfig(CONF_ARENATYPE
, US_SHAREDONLY
);
55 /* Initialize the arena */
56 if (!(__objc_shared_arena_handle
= usinit(arena_name
)))
63 /* Close the threads subsystem. */
65 __objc_close_thread_system(void)
70 /* Backend thread functions */
72 /* Create a new thread of execution. */
74 __objc_thread_detach(void (*func
)(void *arg
), void *arg
)
76 objc_thread_t thread_id
;
79 if ((sys_id
= sproc((void *)func
, PR_SALL
, arg
)) >= 0)
80 thread_id
= (objc_thread_t
)sys_id
;
87 /* Set the current thread's priority. */
89 __objc_thread_set_priority(int priority
)
91 /* Not implemented yet */
95 /* Return the current thread's priority. */
97 __objc_thread_get_priority(void)
99 /* Not implemented yet */
100 return OBJC_THREAD_INTERACTIVE_PRIORITY
;
103 /* Yield our process time to another thread. */
105 __objc_thread_yield(void)
110 /* Terminate the current thread. */
112 __objc_thread_exit(void)
114 /* IRIX only has exit. */
115 exit(__objc_thread_exit_status
);
117 /* Failed if we reached here */
121 /* Returns an integer value which uniquely describes a thread. */
123 __objc_thread_id(void)
125 /* Threads are processes. */
126 return (objc_thread_t
)get_pid();
129 /* Sets the thread's local storage pointer. */
131 __objc_thread_set_data(void *value
)
133 *((void **)&PRDA
->usr_prda
) = value
;
137 /* Returns the thread's local storage pointer. */
139 __objc_thread_get_data(void)
141 return *((void **)&PRDA
->usr_prda
);
144 /* Backend mutex functions */
146 /* Allocate a mutex. */
148 __objc_mutex_allocate(objc_mutex_t mutex
)
150 if (!( (ulock_t
)(mutex
->backend
) = usnewlock(__objc_shared_arena_handle
) ))
156 /* Deallocate a mutex. */
158 __objc_mutex_deallocate(objc_mutex_t mutex
)
160 usfreelock((ulock_t
)(mutex
->backend
), __objc_shared_arena_handle
);
164 /* Grab a lock on a mutex. */
166 __objc_mutex_lock(objc_mutex_t mutex
)
168 if (ussetlock((ulock_t
)(mutex
->backend
)) == 0)
174 /* Try to grab a lock on a mutex. */
176 __objc_mutex_trylock(objc_mutex_t mutex
)
178 if (ustestlock((ulock_t
)(mutex
->backend
)) == 0)
184 /* Unlock the mutex */
186 __objc_mutex_unlock(objc_mutex_t mutex
)
188 usunsetlock((ulock_t
)(mutex
->backend
));
192 /* Backend condition mutex functions */
194 /* Allocate a condition. */
196 __objc_condition_allocate(objc_condition_t condition
)
202 /* Deallocate a condition. */
204 __objc_condition_deallocate(objc_condition_t condition
)
210 /* Wait on the condition */
212 __objc_condition_wait(objc_condition_t condition
, objc_mutex_t mutex
)
218 /* Wake up all threads waiting on this condition. */
220 __objc_condition_broadcast(objc_condition_t condition
)
226 /* Wake up one thread waiting on this condition. */
228 __objc_condition_signal(objc_condition_t condition
)