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
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. */
28 #include "objc/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>
38 #define BOOL _OS2_BOOL
47 /* Backend initialization functions */
49 /* Initialize the threads subsystem. */
51 __objc_init_thread_system(void)
56 /* Close the threads subsystem. */
58 __objc_close_thread_system(void)
63 /* Backend thread functions */
65 /* Create a new thread of execution. */
67 __objc_thread_detach(void (*func
)(void *arg
), void *arg
)
71 if ((thread_id
= _beginthread (func
,NULL
,32768,arg
)) < 0)
74 return (objc_thread_t
)thread_id
;
77 /* Set the current thread's priority. */
79 __objc_thread_set_priority(int priority
)
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 */
89 case OBJC_THREAD_INTERACTIVE_PRIORITY
:
90 sys_class
= PRTYC_REGULAR
;
94 case OBJC_THREAD_BACKGROUND_PRIORITY
:
95 sys_class
= PRTYC_IDLETIME
;
98 case OBJC_THREAD_LOW_PRIORITY
:
99 sys_class
= PRTYC_IDLETIME
;
104 /* Change priority */
105 if (!DosSetPriority (PRTYS_THREAD
,sys_class
,sys_priority
,*_threadid
))
111 /* Return the current thread's priority. */
113 __objc_thread_get_priority(void)
118 /* get information about current thread */
119 DosGetInfoBlocks (&ptib
,&ppib
);
121 switch (ptib
->tib_ptib2
->tib2_ulpri
)
125 case PRTYC_TIMECRITICAL
:
126 case PRTYC_FOREGROUNDSERVER
:
128 return OBJC_THREAD_INTERACTIVE_PRIORITY
;
134 /* Yield our process time to another thread. */
136 __objc_thread_yield(void)
141 /* Terminate the current thread. */
143 __objc_thread_exit(void)
145 /* terminate the thread, NEVER use DosExit () */
148 /* Failed if we reached here */
152 /* Returns an integer value which uniquely describes a thread. */
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
;
168 /* Returns the thread's local storage pointer. */
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)
187 /* Deallocate a mutex. */
189 __objc_mutex_deallocate(objc_mutex_t mutex
)
191 DosCloseMutexSem ((HMTX
)(mutex
->backend
));
195 /* Grab a lock on a mutex. */
197 __objc_mutex_lock(objc_mutex_t mutex
)
199 if (DosRequestMutexSem ((HMTX
)(mutex
->backend
),-1L) != 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)
215 /* Unlock the mutex */
217 __objc_mutex_unlock(objc_mutex_t mutex
)
219 if (DosReleaseMutexSem((HMTX
)(mutex
->backend
)) != 0)
225 /* Backend condition mutex functions */
227 /* Allocate a condition. */
229 __objc_condition_allocate(objc_condition_t condition
)
235 /* Deallocate a condition. */
237 __objc_condition_deallocate(objc_condition_t condition
)
243 /* Wait on the condition */
245 __objc_condition_wait(objc_condition_t condition
, objc_mutex_t mutex
)
251 /* Wake up all threads waiting on this condition. */
253 __objc_condition_broadcast(objc_condition_t condition
)
259 /* Wake up one thread waiting on this condition. */
261 __objc_condition_signal(objc_condition_t condition
)