| 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 |
|
|---|
| 5 | This file is part of GNU CC.
|
|---|
| 6 |
|
|---|
| 7 | GNU CC 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.
|
|---|
| 10 |
|
|---|
| 11 | GNU CC 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 | You should have received a copy of the GNU General Public License along with
|
|---|
| 17 | GNU CC; see the file COPYING. If not, write to the Free Software
|
|---|
| 18 | Foundation, 59 Temple Place - Suite 330,
|
|---|
| 19 | Boston, 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 */
|
|---|
| 36 | static void * __objc_shared_arena_handle = NULL;
|
|---|
| 37 |
|
|---|
| 38 | /* Backend initialization functions */
|
|---|
| 39 |
|
|---|
| 40 | /* Initialize the threads subsystem. */
|
|---|
| 41 | int
|
|---|
| 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. */
|
|---|
| 65 | int
|
|---|
| 66 | __objc_close_thread_system(void)
|
|---|
| 67 | {
|
|---|
| 68 | return 0;
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | /* Backend thread functions */
|
|---|
| 72 |
|
|---|
| 73 | /* Create a new thread of execution. */
|
|---|
| 74 | objc_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. */
|
|---|
| 89 | int
|
|---|
| 90 | __objc_thread_set_priority(int priority)
|
|---|
| 91 | {
|
|---|
| 92 | /* Not implemented yet */
|
|---|
| 93 | return -1;
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | /* Return the current thread's priority. */
|
|---|
| 97 | int
|
|---|
| 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. */
|
|---|
| 105 | void
|
|---|
| 106 | __objc_thread_yield(void)
|
|---|
| 107 | {
|
|---|
| 108 | sginap(0);
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | /* Terminate the current thread. */
|
|---|
| 112 | int
|
|---|
| 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. */
|
|---|
| 123 | objc_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. */
|
|---|
| 131 | int
|
|---|
| 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. */
|
|---|
| 139 | void *
|
|---|
| 140 | __objc_thread_get_data(void)
|
|---|
| 141 | {
|
|---|
| 142 | return *((void **)&PRDA->usr_prda);
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | /* Backend mutex functions */
|
|---|
| 146 |
|
|---|
| 147 | /* Allocate a mutex. */
|
|---|
| 148 | int
|
|---|
| 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. */
|
|---|
| 158 | int
|
|---|
| 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. */
|
|---|
| 166 | int
|
|---|
| 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. */
|
|---|
| 176 | int
|
|---|
| 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 */
|
|---|
| 186 | int
|
|---|
| 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. */
|
|---|
| 196 | int
|
|---|
| 197 | __objc_condition_allocate(objc_condition_t condition)
|
|---|
| 198 | {
|
|---|
| 199 | /* Unimplemented. */
|
|---|
| 200 | return -1;
|
|---|
| 201 | }
|
|---|
| 202 |
|
|---|
| 203 | /* Deallocate a condition. */
|
|---|
| 204 | int
|
|---|
| 205 | __objc_condition_deallocate(objc_condition_t condition)
|
|---|
| 206 | {
|
|---|
| 207 | /* Unimplemented. */
|
|---|
| 208 | return -1;
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | /* Wait on the condition */
|
|---|
| 212 | int
|
|---|
| 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. */
|
|---|
| 220 | int
|
|---|
| 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. */
|
|---|
| 228 | int
|
|---|
| 229 | __objc_condition_signal(objc_condition_t condition)
|
|---|
| 230 | {
|
|---|
| 231 | /* Unimplemented. */
|
|---|
| 232 | return -1;
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | /* End of File */
|
|---|