]>
Commit | Line | Data |
---|---|---|
fc94a55b | 1 | /* GNU Objective C Runtime Thread Interface - OS/2 emx Implementation |
e0d0c8a1 | 2 | Copyright (C) 1996, 1997 Free Software Foundation, Inc. |
cc782a7e | 3 | Contributed by Thomas Baier (baier@ci.tuwien.ac.at) |
fc94a55b RK |
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 | |
17 | along with GNU CC; see the file COPYING. If not, write to | |
18 | the Free Software 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 | ||
cc782a7e RK |
27 | #include <objc/thr.h> |
28 | #include "runtime.h" | |
29 | ||
fc94a55b RK |
30 | #define INCL_DOSSEMAPHORES |
31 | #define INCL_DOSPROCESS | |
32 | ||
33 | /* | |
34 | * conflicts with objc.h: SEL, BOOL, id | |
35 | * solution: prefixing those with _OS2_ before including <os2.h> | |
36 | */ | |
37 | #define SEL _OS2_SEL | |
38 | #define BOOL _OS2_BOOL | |
39 | #define id _OS2_id | |
40 | #include <os2.h> | |
41 | #undef id | |
42 | #undef SEL | |
43 | #undef BOOL | |
44 | ||
45 | #include <stdlib.h> | |
46 | ||
2024f9e4 | 47 | /* Backend initialization functions */ |
fc94a55b | 48 | |
2024f9e4 | 49 | /* Initialize the threads subsystem. */ |
fc94a55b RK |
50 | int |
51 | __objc_init_thread_system(void) | |
52 | { | |
2024f9e4 | 53 | return 0; |
fc94a55b RK |
54 | } |
55 | ||
2024f9e4 | 56 | /* Close the threads subsystem. */ |
fc94a55b | 57 | int |
2024f9e4 | 58 | __objc_close_thread_system(void) |
fc94a55b | 59 | { |
fc94a55b RK |
60 | return 0; |
61 | } | |
62 | ||
2024f9e4 RK |
63 | /* Backend thread functions */ |
64 | ||
65 | /* Create a new thread of execution. */ | |
e0d0c8a1 | 66 | objc_thread_t |
2024f9e4 | 67 | __objc_thread_detach(void (*func)(void *arg), void *arg) |
fc94a55b | 68 | { |
2024f9e4 | 69 | int thread_id = 0; |
fc94a55b | 70 | |
fc94a55b RK |
71 | if ((thread_id = _beginthread (func,NULL,32768,arg)) < 0) |
72 | thread_id = 0; | |
fc94a55b | 73 | |
e0d0c8a1 | 74 | return (objc_thread_t)thread_id; |
fc94a55b RK |
75 | } |
76 | ||
2024f9e4 | 77 | /* Set the current thread's priority. */ |
fc94a55b | 78 | int |
2024f9e4 | 79 | __objc_thread_set_priority(int priority) |
fc94a55b RK |
80 | { |
81 | ULONG sys_class = 0; | |
82 | ULONG sys_priority = 0; | |
83 | ||
84 | /* OBJC_THREAD_INTERACTIVE_PRIORITY -> PRTYC_FOREGROUNDSERVER | |
85 | * OBJC_THREAD_BACKGROUND_PRIORITY -> PRTYC_REGULSR | |
86 | * OBJC_THREAD_LOW_PRIORITY -> PRTYC_IDLETIME */ | |
87 | ||
88 | switch (priority) { | |
89 | case OBJC_THREAD_INTERACTIVE_PRIORITY: | |
90 | sys_class = PRTYC_REGULAR; | |
91 | sys_priority = 10; | |
92 | break; | |
93 | default: | |
94 | case OBJC_THREAD_BACKGROUND_PRIORITY: | |
95 | sys_class = PRTYC_IDLETIME; | |
96 | sys_priority = 25; | |
97 | break; | |
98 | case OBJC_THREAD_LOW_PRIORITY: | |
99 | sys_class = PRTYC_IDLETIME; | |
100 | sys_priority = 0; | |
101 | break; | |
102 | } | |
2024f9e4 RK |
103 | |
104 | /* Change priority */ | |
fc94a55b | 105 | if (!DosSetPriority (PRTYS_THREAD,sys_class,sys_priority,*_threadid)) |
2024f9e4 RK |
106 | return 0; |
107 | else | |
108 | return -1; | |
fc94a55b RK |
109 | } |
110 | ||
2024f9e4 | 111 | /* Return the current thread's priority. */ |
fc94a55b | 112 | int |
2024f9e4 | 113 | __objc_thread_get_priority(void) |
fc94a55b RK |
114 | { |
115 | PTIB ptib; | |
116 | PPIB ppib; | |
117 | ||
2024f9e4 RK |
118 | /* get information about current thread */ |
119 | DosGetInfoBlocks (&ptib,&ppib); | |
120 | ||
121 | switch (ptib->tib_ptib2->tib2_ulpri) | |
122 | { | |
123 | case PRTYC_IDLETIME: | |
124 | case PRTYC_REGULAR: | |
125 | case PRTYC_TIMECRITICAL: | |
126 | case PRTYC_FOREGROUNDSERVER: | |
127 | default: | |
128 | return OBJC_THREAD_INTERACTIVE_PRIORITY; | |
129 | } | |
fc94a55b | 130 | |
2024f9e4 | 131 | return -1; |
fc94a55b RK |
132 | } |
133 | ||
2024f9e4 | 134 | /* Yield our process time to another thread. */ |
fc94a55b | 135 | void |
2024f9e4 | 136 | __objc_thread_yield(void) |
fc94a55b | 137 | { |
2024f9e4 | 138 | DosSleep (0); |
fc94a55b RK |
139 | } |
140 | ||
2024f9e4 | 141 | /* Terminate the current thread. */ |
fc94a55b | 142 | int |
2024f9e4 | 143 | __objc_thread_exit(void) |
fc94a55b | 144 | { |
2024f9e4 RK |
145 | /* terminate the thread, NEVER use DosExit () */ |
146 | _endthread (); | |
fc94a55b | 147 | |
2024f9e4 | 148 | /* Failed if we reached here */ |
fc94a55b RK |
149 | return -1; |
150 | } | |
151 | ||
2024f9e4 | 152 | /* Returns an integer value which uniquely describes a thread. */ |
e0d0c8a1 | 153 | objc_thread_t |
2024f9e4 | 154 | __objc_thread_id(void) |
fc94a55b | 155 | { |
2024f9e4 | 156 | return (objc_thread_t) *_threadid; |
fc94a55b RK |
157 | } |
158 | ||
2024f9e4 | 159 | /* Sets the thread's local storage pointer. */ |
fc94a55b | 160 | int |
2024f9e4 | 161 | __objc_thread_set_data(void *value) |
fc94a55b RK |
162 | { |
163 | *_threadstore () = value; | |
164 | ||
165 | return 0; | |
166 | } | |
167 | ||
2024f9e4 | 168 | /* Returns the thread's local storage pointer. */ |
fc94a55b | 169 | void * |
2024f9e4 | 170 | __objc_thread_get_data(void) |
fc94a55b RK |
171 | { |
172 | return *_threadstore (); | |
173 | } | |
174 | ||
2024f9e4 | 175 | /* Backend mutex functions */ |
fc94a55b | 176 | |
2024f9e4 RK |
177 | /* Allocate a mutex. */ |
178 | int | |
179 | __objc_mutex_allocate(objc_mutex_t mutex) | |
180 | { | |
181 | if (DosCreateMutexSem (NULL, (HMTX)(&(mutex->backend)),0L,0) > 0) | |
182 | return -1; | |
183 | else | |
184 | return 0; | |
fc94a55b RK |
185 | } |
186 | ||
2024f9e4 | 187 | /* Deallocate a mutex. */ |
fc94a55b | 188 | int |
2024f9e4 | 189 | __objc_mutex_deallocate(objc_mutex_t mutex) |
fc94a55b | 190 | { |
2024f9e4 RK |
191 | DosCloseMutexSem ((HMTX)(mutex->backend)); |
192 | return 0; | |
fc94a55b RK |
193 | } |
194 | ||
2024f9e4 | 195 | /* Grab a lock on a mutex. */ |
fc94a55b | 196 | int |
2024f9e4 | 197 | __objc_mutex_lock(objc_mutex_t mutex) |
fc94a55b | 198 | { |
2024f9e4 RK |
199 | if (DosRequestMutexSem ((HMTX)(mutex->backend),-1L) != 0) |
200 | return -1; | |
201 | else | |
202 | return 0; | |
203 | } | |
fc94a55b | 204 | |
2024f9e4 RK |
205 | /* Try to grab a lock on a mutex. */ |
206 | int | |
207 | __objc_mutex_trylock(objc_mutex_t mutex) | |
208 | { | |
209 | if (DosRequestMutexSem ((HMTX)(mutex->backend),0L) != 0) | |
210 | return -1; | |
211 | else | |
212 | return 0; | |
213 | } | |
fc94a55b | 214 | |
2024f9e4 RK |
215 | /* Unlock the mutex */ |
216 | int | |
217 | __objc_mutex_unlock(objc_mutex_t mutex) | |
218 | { | |
219 | if (DosReleaseMutexSem((HMTX)(mutex->backend)) != 0) | |
220 | return -1; | |
221 | else | |
222 | return 0; | |
223 | } | |
fc94a55b | 224 | |
2024f9e4 | 225 | /* Backend condition mutex functions */ |
fc94a55b | 226 | |
2024f9e4 RK |
227 | /* Allocate a condition. */ |
228 | int | |
229 | __objc_condition_allocate(objc_condition_t condition) | |
230 | { | |
231 | /* Unimplemented. */ | |
232 | return -1; | |
fc94a55b RK |
233 | } |
234 | ||
2024f9e4 | 235 | /* Deallocate a condition. */ |
fc94a55b | 236 | int |
2024f9e4 | 237 | __objc_condition_deallocate(objc_condition_t condition) |
fc94a55b | 238 | { |
2024f9e4 RK |
239 | /* Unimplemented. */ |
240 | return -1; | |
241 | } | |
fc94a55b | 242 | |
2024f9e4 RK |
243 | /* Wait on the condition */ |
244 | int | |
245 | __objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex) | |
246 | { | |
247 | /* Unimplemented. */ | |
248 | return -1; | |
249 | } | |
fc94a55b | 250 | |
2024f9e4 RK |
251 | /* Wake up all threads waiting on this condition. */ |
252 | int | |
253 | __objc_condition_broadcast(objc_condition_t condition) | |
254 | { | |
255 | /* Unimplemented. */ | |
256 | return -1; | |
fc94a55b RK |
257 | } |
258 | ||
2024f9e4 | 259 | /* Wake up one thread waiting on this condition. */ |
fc94a55b | 260 | int |
2024f9e4 | 261 | __objc_condition_signal(objc_condition_t condition) |
fc94a55b | 262 | { |
2024f9e4 RK |
263 | /* Unimplemented. */ |
264 | return -1; | |
fc94a55b | 265 | } |
2024f9e4 RK |
266 | |
267 | /* End of File */ |