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
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/>. */
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>
37 #define BOOL _OS2_BOOL
46 /* Backend initialization functions */
48 /* Initialize the threads subsystem. */
50 __objc_init_thread_system(void)
55 /* Close the threads subsystem. */
57 __objc_close_thread_system(void)
62 /* Backend thread functions */
64 /* Create a new thread of execution. */
66 __objc_thread_detach(void (*func
)(void *arg
), void *arg
)
70 if ((thread_id
= _beginthread (func
,NULL
,32768,arg
)) < 0)
73 return (objc_thread_t
)thread_id
;
76 /* Set the current thread's priority. */
78 __objc_thread_set_priority(int priority
)
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 */
88 case OBJC_THREAD_INTERACTIVE_PRIORITY
:
89 sys_class
= PRTYC_REGULAR
;
93 case OBJC_THREAD_BACKGROUND_PRIORITY
:
94 sys_class
= PRTYC_IDLETIME
;
97 case OBJC_THREAD_LOW_PRIORITY
:
98 sys_class
= PRTYC_IDLETIME
;
103 /* Change priority */
104 if (!DosSetPriority (PRTYS_THREAD
,sys_class
,sys_priority
,*_threadid
))
110 /* Return the current thread's priority. */
112 __objc_thread_get_priority(void)
117 /* get information about current thread */
118 DosGetInfoBlocks (&ptib
,&ppib
);
120 switch (ptib
->tib_ptib2
->tib2_ulpri
)
124 case PRTYC_TIMECRITICAL
:
125 case PRTYC_FOREGROUNDSERVER
:
127 return OBJC_THREAD_INTERACTIVE_PRIORITY
;
133 /* Yield our process time to another thread. */
135 __objc_thread_yield(void)
140 /* Terminate the current thread. */
142 __objc_thread_exit(void)
144 /* terminate the thread, NEVER use DosExit () */
147 /* Failed if we reached here */
151 /* Returns an integer value which uniquely describes a thread. */
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
;
167 /* Returns the thread's local storage pointer. */
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)
186 /* Deallocate a mutex. */
188 __objc_mutex_deallocate(objc_mutex_t mutex
)
190 DosCloseMutexSem ((HMTX
)(mutex
->backend
));
194 /* Grab a lock on a mutex. */
196 __objc_mutex_lock(objc_mutex_t mutex
)
198 if (DosRequestMutexSem ((HMTX
)(mutex
->backend
),-1L) != 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)
214 /* Unlock the mutex */
216 __objc_mutex_unlock(objc_mutex_t mutex
)
218 if (DosReleaseMutexSem((HMTX
)(mutex
->backend
)) != 0)
224 /* Backend condition mutex functions */
226 /* Allocate a condition. */
228 __objc_condition_allocate(objc_condition_t condition
)
234 /* Deallocate a condition. */
236 __objc_condition_deallocate(objc_condition_t condition
)
242 /* Wait on the condition */
244 __objc_condition_wait(objc_condition_t condition
, objc_mutex_t mutex
)
250 /* Wake up all threads waiting on this condition. */
252 __objc_condition_broadcast(objc_condition_t condition
)
258 /* Wake up one thread waiting on this condition. */
260 __objc_condition_signal(objc_condition_t condition
)