Daily bump.
[official-gcc.git] / libobjc / thr-os2.c
blob1f9e3ae5ceab9b8a924ef3e7e47bfc0b6bb784f7
1 /* GNU Objective C Runtime Thread Interface - OS/2 emx Implementation
2 Copyright (C) 1996, 1997, 2009 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 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 "objc/thr.h"
27 #include "objc/runtime.h"
29 #define INCL_DOSSEMAPHORES
30 #define INCL_DOSPROCESS
33 * conflicts with objc.h: SEL, BOOL, id
34 * solution: prefixing those with _OS2_ before including <os2.h>
36 #define SEL _OS2_SEL
37 #define BOOL _OS2_BOOL
38 #define id _OS2_id
39 #include <os2.h>
40 #undef id
41 #undef SEL
42 #undef BOOL
44 #include <stdlib.h>
46 /* Backend initialization functions */
48 /* Initialize the threads subsystem. */
49 int
50 __objc_init_thread_system(void)
52 return 0;
55 /* Close the threads subsystem. */
56 int
57 __objc_close_thread_system(void)
59 return 0;
62 /* Backend thread functions */
64 /* Create a new thread of execution. */
65 objc_thread_t
66 __objc_thread_detach(void (*func)(void *arg), void *arg)
68 int thread_id = 0;
70 if ((thread_id = _beginthread (func,NULL,32768,arg)) < 0)
71 thread_id = 0;
73 return (objc_thread_t)thread_id;
76 /* Set the current thread's priority. */
77 int
78 __objc_thread_set_priority(int priority)
80 ULONG sys_class = 0;
81 ULONG sys_priority = 0;
83 /* OBJC_THREAD_INTERACTIVE_PRIORITY -> PRTYC_FOREGROUNDSERVER
84 * OBJC_THREAD_BACKGROUND_PRIORITY -> PRTYC_REGULAR
85 * OBJC_THREAD_LOW_PRIORITY -> PRTYC_IDLETIME */
87 switch (priority) {
88 case OBJC_THREAD_INTERACTIVE_PRIORITY:
89 sys_class = PRTYC_REGULAR;
90 sys_priority = 10;
91 break;
92 default:
93 case OBJC_THREAD_BACKGROUND_PRIORITY:
94 sys_class = PRTYC_IDLETIME;
95 sys_priority = 25;
96 break;
97 case OBJC_THREAD_LOW_PRIORITY:
98 sys_class = PRTYC_IDLETIME;
99 sys_priority = 0;
100 break;
103 /* Change priority */
104 if (!DosSetPriority (PRTYS_THREAD,sys_class,sys_priority,*_threadid))
105 return 0;
106 else
107 return -1;
110 /* Return the current thread's priority. */
112 __objc_thread_get_priority(void)
114 PTIB ptib;
115 PPIB ppib;
117 /* get information about current thread */
118 DosGetInfoBlocks (&ptib,&ppib);
120 switch (ptib->tib_ptib2->tib2_ulpri)
122 case PRTYC_IDLETIME:
123 case PRTYC_REGULAR:
124 case PRTYC_TIMECRITICAL:
125 case PRTYC_FOREGROUNDSERVER:
126 default:
127 return OBJC_THREAD_INTERACTIVE_PRIORITY;
130 return -1;
133 /* Yield our process time to another thread. */
134 void
135 __objc_thread_yield(void)
137 DosSleep (0);
140 /* Terminate the current thread. */
142 __objc_thread_exit(void)
144 /* terminate the thread, NEVER use DosExit () */
145 _endthread ();
147 /* Failed if we reached here */
148 return -1;
151 /* Returns an integer value which uniquely describes a thread. */
152 objc_thread_t
153 __objc_thread_id(void)
155 return (objc_thread_t) *_threadid;
158 /* Sets the thread's local storage pointer. */
160 __objc_thread_set_data(void *value)
162 *_threadstore () = value;
164 return 0;
167 /* Returns the thread's local storage pointer. */
168 void *
169 __objc_thread_get_data(void)
171 return *_threadstore ();
174 /* Backend mutex functions */
176 /* Allocate a mutex. */
178 __objc_mutex_allocate(objc_mutex_t mutex)
180 if (DosCreateMutexSem (NULL, (HMTX)(&(mutex->backend)),0L,0) > 0)
181 return -1;
182 else
183 return 0;
186 /* Deallocate a mutex. */
188 __objc_mutex_deallocate(objc_mutex_t mutex)
190 DosCloseMutexSem ((HMTX)(mutex->backend));
191 return 0;
194 /* Grab a lock on a mutex. */
196 __objc_mutex_lock(objc_mutex_t mutex)
198 if (DosRequestMutexSem ((HMTX)(mutex->backend),-1L) != 0)
199 return -1;
200 else
201 return 0;
204 /* Try to grab a lock on a mutex. */
206 __objc_mutex_trylock(objc_mutex_t mutex)
208 if (DosRequestMutexSem ((HMTX)(mutex->backend),0L) != 0)
209 return -1;
210 else
211 return 0;
214 /* Unlock the mutex */
216 __objc_mutex_unlock(objc_mutex_t mutex)
218 if (DosReleaseMutexSem((HMTX)(mutex->backend)) != 0)
219 return -1;
220 else
221 return 0;
224 /* Backend condition mutex functions */
226 /* Allocate a condition. */
228 __objc_condition_allocate(objc_condition_t condition)
230 /* Unimplemented. */
231 return -1;
234 /* Deallocate a condition. */
236 __objc_condition_deallocate(objc_condition_t condition)
238 /* Unimplemented. */
239 return -1;
242 /* Wait on the condition */
244 __objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex)
246 /* Unimplemented. */
247 return -1;
250 /* Wake up all threads waiting on this condition. */
252 __objc_condition_broadcast(objc_condition_t condition)
254 /* Unimplemented. */
255 return -1;
258 /* Wake up one thread waiting on this condition. */
260 __objc_condition_signal(objc_condition_t condition)
262 /* Unimplemented. */
263 return -1;
266 /* End of File */