[multiple changes]
[official-gcc.git] / libobjc / thr-os2.c
blobd43d225650cd7d065c7fc8ee334304ee71ee0219
1 /* GNU Objective C Runtime Thread Interface - OS/2 emx Implementation
2 Copyright (C) 1996, 1997 Free Software Foundation, Inc.
3 Contributed by Thomas Baier (baier@ci.tuwien.ac.at)
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
14 details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to
18 the Free Software 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. */
27 #include <objc/thr.h>
28 #include "runtime.h"
30 #define INCL_DOSSEMAPHORES
31 #define INCL_DOSPROCESS
34 * conflicts with objc.h: SEL, BOOL, id
35 * solution: prefixing those with _OS2_ before including <os2.h>
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
45 #include <stdlib.h>
47 /* Backend initialization functions */
49 /* Initialize the threads subsystem. */
50 int
51 __objc_init_thread_system(void)
53 return 0;
56 /* Close the threads subsystem. */
57 int
58 __objc_close_thread_system(void)
60 return 0;
63 /* Backend thread functions */
65 /* Create a new thread of execution. */
66 objc_thread_t
67 __objc_thread_detach(void (*func)(void *arg), void *arg)
69 int thread_id = 0;
71 if ((thread_id = _beginthread (func,NULL,32768,arg)) < 0)
72 thread_id = 0;
74 return (objc_thread_t)thread_id;
77 /* Set the current thread's priority. */
78 int
79 __objc_thread_set_priority(int priority)
81 ULONG sys_class = 0;
82 ULONG sys_priority = 0;
84 /* OBJC_THREAD_INTERACTIVE_PRIORITY -> PRTYC_FOREGROUNDSERVER
85 * OBJC_THREAD_BACKGROUND_PRIORITY -> PRTYC_REGULAR
86 * OBJC_THREAD_LOW_PRIORITY -> PRTYC_IDLETIME */
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;
104 /* Change priority */
105 if (!DosSetPriority (PRTYS_THREAD,sys_class,sys_priority,*_threadid))
106 return 0;
107 else
108 return -1;
111 /* Return the current thread's priority. */
113 __objc_thread_get_priority(void)
115 PTIB ptib;
116 PPIB ppib;
118 /* get information about current thread */
119 DosGetInfoBlocks (&ptib,&ppib);
121 switch (ptib->tib_ptib2->tib2_ulpri)
123 case PRTYC_IDLETIME:
124 case PRTYC_REGULAR:
125 case PRTYC_TIMECRITICAL:
126 case PRTYC_FOREGROUNDSERVER:
127 default:
128 return OBJC_THREAD_INTERACTIVE_PRIORITY;
131 return -1;
134 /* Yield our process time to another thread. */
135 void
136 __objc_thread_yield(void)
138 DosSleep (0);
141 /* Terminate the current thread. */
143 __objc_thread_exit(void)
145 /* terminate the thread, NEVER use DosExit () */
146 _endthread ();
148 /* Failed if we reached here */
149 return -1;
152 /* Returns an integer value which uniquely describes a thread. */
153 objc_thread_t
154 __objc_thread_id(void)
156 return (objc_thread_t) *_threadid;
159 /* Sets the thread's local storage pointer. */
161 __objc_thread_set_data(void *value)
163 *_threadstore () = value;
165 return 0;
168 /* Returns the thread's local storage pointer. */
169 void *
170 __objc_thread_get_data(void)
172 return *_threadstore ();
175 /* Backend mutex functions */
177 /* Allocate a mutex. */
179 __objc_mutex_allocate(objc_mutex_t mutex)
181 if (DosCreateMutexSem (NULL, (HMTX)(&(mutex->backend)),0L,0) > 0)
182 return -1;
183 else
184 return 0;
187 /* Deallocate a mutex. */
189 __objc_mutex_deallocate(objc_mutex_t mutex)
191 DosCloseMutexSem ((HMTX)(mutex->backend));
192 return 0;
195 /* Grab a lock on a mutex. */
197 __objc_mutex_lock(objc_mutex_t mutex)
199 if (DosRequestMutexSem ((HMTX)(mutex->backend),-1L) != 0)
200 return -1;
201 else
202 return 0;
205 /* Try to grab a lock on a mutex. */
207 __objc_mutex_trylock(objc_mutex_t mutex)
209 if (DosRequestMutexSem ((HMTX)(mutex->backend),0L) != 0)
210 return -1;
211 else
212 return 0;
215 /* Unlock the mutex */
217 __objc_mutex_unlock(objc_mutex_t mutex)
219 if (DosReleaseMutexSem((HMTX)(mutex->backend)) != 0)
220 return -1;
221 else
222 return 0;
225 /* Backend condition mutex functions */
227 /* Allocate a condition. */
229 __objc_condition_allocate(objc_condition_t condition)
231 /* Unimplemented. */
232 return -1;
235 /* Deallocate a condition. */
237 __objc_condition_deallocate(objc_condition_t condition)
239 /* Unimplemented. */
240 return -1;
243 /* Wait on the condition */
245 __objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex)
247 /* Unimplemented. */
248 return -1;
251 /* Wake up all threads waiting on this condition. */
253 __objc_condition_broadcast(objc_condition_t condition)
255 /* Unimplemented. */
256 return -1;
259 /* Wake up one thread waiting on this condition. */
261 __objc_condition_signal(objc_condition_t condition)
263 /* Unimplemented. */
264 return -1;
267 /* End of File */