source: branches/libc-0.6/src/gcc/libobjc/thr-os2.c

Last change on this file was 9, checked in by bird, 22 years ago

Applied initial diff from Platon.

  • Property cvs2svn:cvs-rev set to 1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 5.5 KB
Line 
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)
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify it under the
8terms of the GNU General Public License as published by the Free Software
9Foundation; either version 2, or (at your option) any later version.
10
11GNU CC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14details.
15
16You should have received a copy of the GNU General Public License
17along with GNU CC; see the file COPYING. If not, write to
18the Free Software Foundation, 59 Temple Place - Suite 330,
19Boston, 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
27#include <objc/thr.h>
28#include "runtime.h"
29
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#define __MT__
46#include <stdlib.h>
47
48/* Backend initialization functions */
49
50/* Initialize the threads subsystem. */
51int
52__objc_init_thread_system(void)
53{
54 return 0;
55}
56
57/* Close the threads subsystem. */
58int
59__objc_close_thread_system(void)
60{
61 return 0;
62}
63
64/* Backend thread functions */
65
66/* Create a new thread of execution. */
67objc_thread_t
68__objc_thread_detach(void (*func)(void *arg), void *arg)
69{
70 int thread_id = 0;
71
72 if ((thread_id = _beginthread (func,NULL,32768,arg)) < 0)
73 thread_id = 0;
74
75 return (objc_thread_t)thread_id;
76}
77
78/* Set the current thread's priority. */
79int
80__objc_thread_set_priority(int priority)
81{
82 ULONG sys_class = 0;
83 ULONG sys_priority = 0;
84
85 /* OBJC_THREAD_INTERACTIVE_PRIORITY -> PRTYC_FOREGROUNDSERVER
86 * OBJC_THREAD_BACKGROUND_PRIORITY -> PRTYC_REGULAR
87 * OBJC_THREAD_LOW_PRIORITY -> PRTYC_IDLETIME */
88
89 switch (priority) {
90 case OBJC_THREAD_INTERACTIVE_PRIORITY:
91 sys_class = PRTYC_REGULAR;
92 sys_priority = 10;
93 break;
94 default:
95 case OBJC_THREAD_BACKGROUND_PRIORITY:
96 sys_class = PRTYC_IDLETIME;
97 sys_priority = 25;
98 break;
99 case OBJC_THREAD_LOW_PRIORITY:
100 sys_class = PRTYC_IDLETIME;
101 sys_priority = 0;
102 break;
103 }
104
105 /* Change priority */
106 if (!DosSetPriority (PRTYS_THREAD,sys_class,sys_priority,*_threadid))
107 return 0;
108 else
109 return -1;
110}
111
112/* Return the current thread's priority. */
113int
114__objc_thread_get_priority(void)
115{
116 PTIB ptib;
117 PPIB ppib;
118
119 /* get information about current thread */
120 DosGetInfoBlocks (&ptib,&ppib);
121
122 switch (ptib->tib_ptib2->tib2_ulpri)
123 {
124 case PRTYC_IDLETIME:
125 case PRTYC_REGULAR:
126 case PRTYC_TIMECRITICAL:
127 case PRTYC_FOREGROUNDSERVER:
128 default:
129 return OBJC_THREAD_INTERACTIVE_PRIORITY;
130 }
131
132 return -1;
133}
134
135/* Yield our process time to another thread. */
136void
137__objc_thread_yield(void)
138{
139 DosSleep (0);
140}
141
142/* Terminate the current thread. */
143int
144__objc_thread_exit(void)
145{
146 /* terminate the thread, NEVER use DosExit () */
147 _endthread ();
148
149 /* Failed if we reached here */
150 return -1;
151}
152
153/* Returns an integer value which uniquely describes a thread. */
154objc_thread_t
155__objc_thread_id(void)
156{
157 return (objc_thread_t) *_threadid;
158}
159
160/* Sets the thread's local storage pointer. */
161int
162__objc_thread_set_data(void *value)
163{
164 *_threadstore () = value;
165
166 return 0;
167}
168
169/* Returns the thread's local storage pointer. */
170void *
171__objc_thread_get_data(void)
172{
173 return *_threadstore ();
174}
175
176/* Backend mutex functions */
177
178/* Allocate a mutex. */
179int
180__objc_mutex_allocate(objc_mutex_t mutex)
181{
182 if (DosCreateMutexSem (NULL, (PHMTX)(&(mutex->backend)),0L,0) > 0)
183 return -1;
184 else
185 return 0;
186}
187
188/* Deallocate a mutex. */
189int
190__objc_mutex_deallocate(objc_mutex_t mutex)
191{
192 DosCloseMutexSem ((HMTX)(mutex->backend));
193 return 0;
194}
195
196/* Grab a lock on a mutex. */
197int
198__objc_mutex_lock(objc_mutex_t mutex)
199{
200 if (DosRequestMutexSem ((HMTX)(mutex->backend),-1L) != 0)
201 return -1;
202 else
203 return 0;
204}
205
206/* Try to grab a lock on a mutex. */
207int
208__objc_mutex_trylock(objc_mutex_t mutex)
209{
210 if (DosRequestMutexSem ((HMTX)(mutex->backend),0L) != 0)
211 return -1;
212 else
213 return 0;
214}
215
216/* Unlock the mutex */
217int
218__objc_mutex_unlock(objc_mutex_t mutex)
219{
220 if (DosReleaseMutexSem((HMTX)(mutex->backend)) != 0)
221 return -1;
222 else
223 return 0;
224}
225
226/* Backend condition mutex functions */
227
228/* Allocate a condition. */
229int
230__objc_condition_allocate(objc_condition_t condition)
231{
232 /* Unimplemented. */
233 return -1;
234}
235
236/* Deallocate a condition. */
237int
238__objc_condition_deallocate(objc_condition_t condition)
239{
240 /* Unimplemented. */
241 return -1;
242}
243
244/* Wait on the condition */
245int
246__objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex)
247{
248 /* Unimplemented. */
249 return -1;
250}
251
252/* Wake up all threads waiting on this condition. */
253int
254__objc_condition_broadcast(objc_condition_t condition)
255{
256 /* Unimplemented. */
257 return -1;
258}
259
260/* Wake up one thread waiting on this condition. */
261int
262__objc_condition_signal(objc_condition_t condition)
263{
264 /* Unimplemented. */
265 return -1;
266}
267
268/* End of File */
Note: See TracBrowser for help on using the repository browser.