PR libfortran/43605 FTELL intrinsic, take 2.
[official-gcc.git] / libobjc / thr-irix.c
blob84a5fc1da987248aa3f4a53e077e0fbe6a0895fb
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
14 details.
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/>. */
26 #include <stdlib.h>
27 #include <sys/types.h>
28 #include <sys/sysmp.h>
29 #include <sys/prctl.h>
30 #include <ulocks.h>
31 #include "objc/thr.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. */
40 int
41 __objc_init_thread_system(void)
43 /* Name of IRIX arena. */
44 char arena_name[64];
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)))
57 /* Failed */
58 return -1;
60 return 0;
63 /* Close the threads subsystem. */
64 int
65 __objc_close_thread_system(void)
67 return 0;
70 /* Backend thread functions */
72 /* Create a new thread of execution. */
73 objc_thread_t
74 __objc_thread_detach(void (*func)(void *arg), void *arg)
76 objc_thread_t thread_id;
77 int sys_id;
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;
84 return thread_id;
87 /* Set the current thread's priority. */
88 int
89 __objc_thread_set_priority(int priority)
91 /* Not implemented yet */
92 return -1;
95 /* Return the current thread's priority. */
96 int
97 __objc_thread_get_priority(void)
99 /* Not implemented yet */
100 return OBJC_THREAD_INTERACTIVE_PRIORITY;
103 /* Yield our process time to another thread. */
104 void
105 __objc_thread_yield(void)
107 sginap(0);
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 */
118 return -1;
121 /* Returns an integer value which uniquely describes a thread. */
122 objc_thread_t
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;
134 return 0;
137 /* Returns the thread's local storage pointer. */
138 void *
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) ))
151 return -1;
152 else
153 return 0;
156 /* Deallocate a mutex. */
158 __objc_mutex_deallocate(objc_mutex_t mutex)
160 usfreelock((ulock_t)(mutex->backend), __objc_shared_arena_handle);
161 return 0;
164 /* Grab a lock on a mutex. */
166 __objc_mutex_lock(objc_mutex_t mutex)
168 if (ussetlock((ulock_t)(mutex->backend)) == 0)
169 return -1;
170 else
171 return 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)
179 return -1;
180 else
181 return 0;
184 /* Unlock the mutex */
186 __objc_mutex_unlock(objc_mutex_t mutex)
188 usunsetlock((ulock_t)(mutex->backend));
189 return 0;
192 /* Backend condition mutex functions */
194 /* Allocate a condition. */
196 __objc_condition_allocate(objc_condition_t condition)
198 /* Unimplemented. */
199 return -1;
202 /* Deallocate a condition. */
204 __objc_condition_deallocate(objc_condition_t condition)
206 /* Unimplemented. */
207 return -1;
210 /* Wait on the condition */
212 __objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex)
214 /* Unimplemented. */
215 return -1;
218 /* Wake up all threads waiting on this condition. */
220 __objc_condition_broadcast(objc_condition_t condition)
222 /* Unimplemented. */
223 return -1;
226 /* Wake up one thread waiting on this condition. */
228 __objc_condition_signal(objc_condition_t condition)
230 /* Unimplemented. */
231 return -1;
234 /* End of File */