/[eiffelstudio]/branches/eth/eve/Src/C/run-time/eif_posix_threads.h
ViewVC logotype

Contents of /branches/eth/eve/Src/C/run-time/eif_posix_threads.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 94983 - (show annotations)
Fri May 2 11:05:28 2014 UTC (5 years, 5 months ago) by jasonw
File MIME type: text/plain
File size: 8858 byte(s)
<<Merged from trunk#94978.>>
1 /*
2 description: "Thread management routines."
3 date: "$Date$"
4 revision: "$Revision$"
5 copyright: "Copyright (c) 1985-2006, Eiffel Software."
6 license: "GPL version 2 see http://www.eiffel.com/licensing/gpl.txt)"
7 licensing_options: "Commercial license is available at http://www.eiffel.com/licensing"
8 copying: "[
9 This file is part of Eiffel Software's Runtime.
10
11 Eiffel Software's Runtime is free software; you can
12 redistribute it and/or modify it under the terms of the
13 GNU General Public License as published by the Free
14 Software Foundation, version 2 of the License
15 (available at the URL listed under "license" above).
16
17 Eiffel Software's Runtime is distributed in the hope
18 that it will be useful, but WITHOUT ANY WARRANTY;
19 without even the implied warranty of MERCHANTABILITY
20 or FITNESS FOR A PARTICULAR PURPOSE.
21 See the GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public
24 License along with Eiffel Software's Runtime; if not,
25 write to the Free Software Foundation, Inc.,
26 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 ]"
28 source: "[
29 Eiffel Software
30 356 Storke Road, Goleta, CA 93117 USA
31 Telephone 805-685-1006, Fax 805-685-6869
32 Website http://www.eiffel.com
33 Customer support http://support.eiffel.com
34 ]"
35 */
36
37 #ifndef _eif_posix_threads_h_
38 #define _eif_posix_threads_h_
39 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
40 #pragma once
41 #endif
42
43 #ifdef EIF_THREADS
44
45 #include "eif_portable.h"
46
47 /*------------------------------------*/
48 /*----- Platform specific tuning -----*/
49 /*------------------------------------*/
50
51 #ifdef EIF_LINUXTHREADS /* Tuning for POSIX LinuxThreads */
52 #define EIF_POSIX_THREADS
53 #ifndef EIF_DFL_SIGUSR
54 #define EIF_DFLT_SIGUSR
55 #endif
56 #endif
57
58 #ifdef EIF_WINDOWS
59 #define EIF_NO_NATIVE_COND
60 #define EIF_NO_POSIX_SEM
61 #endif
62
63 #ifdef VXWORKS /* Tuning for VxWorks */
64 #define EIF_NO_NATIVE_COND
65 #define EIF_NO_POSIX_SEM
66 #endif
67
68 #ifdef EIF_VMS /* VMS supports POSIX 1003.1c threads */
69 #define EIF_POSIX_THREADS
70 #define HASNT_SCHED_H
71 #define HASNT_SEMAPHORE_H
72 #endif
73
74 /* POSIX specifics. */
75 #ifdef EIF_POSIX_THREADS
76 #define HAS_THREAD_CANCELLATION
77 #define EIF_THR_CANCEL(tid) pthread_cancel(tid)
78 /*
79 * Posix 1003.1b signals
80 */
81 #if (_POSIX_C_SOURCE==199309L)
82 #ifdef SIGRTMIN
83 #define EIF_DFLT_SIGRTMIN
84 #endif
85 #ifdef SIGRTMAX
86 #define EIF_DFLT_SIGRTMAX
87 #endif
88 #endif /* _POSIX_C_SOURCE */
89
90 /*
91 * Signals reserved for Posix 1003.1c.
92 */
93 #if (_POSIX_C_SOURCE==199506L)
94 #ifdef SIGPTINTR
95 #define EIF_DFLT_SIGPTINTR
96 #endif
97 #ifdef SIGPTRESCHED
98 #define EIF_DFLT_SIGPTRESCHED
99 #endif
100 #endif /* _POSIX_C_SOURCE */
101 #endif
102
103
104
105 /*---------------------------*/
106 /*---- Header inclusion -----*/
107 /*---------------------------*/
108
109 #if defined(EIF_POSIX_THREADS) || defined(SOLARIS_THREADS)
110
111 #ifdef EIF_POSIX_THREADS
112 #include <pthread.h>
113 #elif defined(SOLARIS_THREADS)
114 #include <thread.h>
115 #endif
116
117 #ifndef HASNT_SCHED_H
118 #include <sched.h>
119 #endif
120
121 #ifdef NEED_SYNCH_H
122 #include <synch.h>
123 #endif
124
125 #elif defined EIF_WINDOWS
126 #include <windows.h>
127 #include <process.h>
128
129 #elif defined VXWORKS
130 #include <taskLib.h> /* 'thread' operations */
131 #include <taskVarLib.h> /* 'thread' 'specific data' */
132 #include <semLib.h> /* 'mutexes' and semaphores */
133 #include <sched.h> /* 'sched_yield' */
134
135 #endif
136
137 #ifndef EIF_NO_POSIX_SEM /* Defaults for semaphore */
138 #ifndef HASNT_SEMAPHORE_H
139 #include <semaphore.h>
140 #endif
141 #endif
142
143 #ifdef __cplusplus
144 extern "C" {
145 #endif
146
147 /*------------------------------*/
148 /*----- Type definitions -----*/
149 /*------------------------------*/
150
151 rt_public typedef struct {
152 rt_uint_ptr priority;
153 rt_uint_ptr stack_size;
154 } EIF_THR_ATTR_TYPE;
155
156 #ifdef EIF_POSIX_THREADS
157 #define EIF_THR_TYPE pthread_t
158 #define EIF_CS_TYPE pthread_mutex_t
159 #define EIF_MUTEX_TYPE pthread_mutex_t
160 #define EIF_COND_TYPE pthread_cond_t
161 #if (EIF_OS == EIF_OS_DARWIN) || (EIF_OS == EIF_OS_IPHONE)
162 rt_public typedef struct {
163 EIF_MUTEX_TYPE *mutex;
164 EIF_COND_TYPE *cond;
165 unsigned int val;
166 } EIF_SEM_TYPE;
167 #else
168 #define EIF_SEM_TYPE sem_t
169 #endif
170 #define EIF_RWL_TYPE pthread_rwlock_t
171
172 #elif defined SOLARIS_THREADS
173 #define EIF_THR_TYPE thread_t
174 #define EIF_CS_TYPE lwp_mutex_t
175 #define EIF_MUTEX_TYPE mutex_t
176 #define EIF_SEM_TYPE sema_t
177 #define EIF_COND_TYPE cond_t
178 #define EIF_RWL_TYPE rwlock_t
179
180 #elif defined(EIF_WINDOWS)
181 #define EIF_THR_TYPE HANDLE
182 #define EIF_CS_TYPE CRITICAL_SECTION
183 #define EIF_MUTEX_TYPE CRITICAL_SECTION
184 #define EIF_SEM_TYPE HANDLE
185
186 #elif defined VXWORKS
187 /* For consistency with the other platforms, EIF_.._TYPE shouldn't
188 be a pointer, that's why we use struct semaphore instead of SEM_ID
189 because SEM_ID is equivalent to (struct semaphore *) */
190 #define EIF_THR_TYPE int
191 #define EIF_CS_TYPE struct semaphore
192 #define EIF_MUTEX_TYPE struct semaphore
193 #define EIF_SEM_TYPE struct semaphore
194 #endif
195
196 #ifdef EIF_NO_NATIVE_COND
197 rt_public typedef struct {
198 /* Semaphore used to queue up threads waiting for the condition to become signaled. */
199 EIF_SEM_TYPE *semaphore;
200 /* Serialize access to fields of Current. */
201 EIF_CS_TYPE *csection;
202 /* Number of waiters. */
203 unsigned long num_waiting;
204 /* Number of already awoken. */
205 unsigned long num_wake;
206 /* Number of time we signaled/broadcasted for improving fairness.
207 * This ensures one thread won't steal wakeups from other threads in queue. */
208 unsigned long generation;
209 } EIF_COND_TYPE;
210 #endif
211
212 /* Definition of Read/Write lock structure for platforms that do not provide one. */
213 #ifdef EIF_POSIX_THREADS
214 #elif defined(SOLARIS_THREADS)
215 #else
216 rt_public typedef struct {
217 EIF_MUTEX_TYPE *m; /* Internal monitor lock. */
218 int rwlock; /* >0 = # readers, <0 = writer, 0 = none */
219 EIF_COND_TYPE *readers_ok; /* Start waiting readers. */
220 unsigned int waiting_writers; /* Number of waiting writers. */
221 EIF_COND_TYPE *writers_ok; /* Start a waiting writer. */
222 } EIF_RWL_TYPE;
223 #endif
224
225 #define EIF_MIN_THR_PRIORITY 0L
226 #define EIF_BELOW_NORMAL_THR_PRIORITY 100L
227 #define EIF_DEFAULT_THR_PRIORITY 127L
228 #define EIF_ABOVE_NORMAL_THR_PRIORITY 154L
229 #define EIF_MAX_THR_PRIORITY 255L
230
231 /* Thread routines */
232 #ifdef EIF_WINDOWS
233 extern DWORD eif_pthread_current_id (void);
234 #endif
235 extern int eif_pthread_create (EIF_THR_TYPE *thread_id, EIF_THR_ATTR_TYPE *thread_attr, void (*thread_routine) (void *), void *thread_arg);
236 extern int eif_pthread_kill (EIF_THR_TYPE thread_id);
237 extern int eif_pthread_exit (EIF_THR_TYPE thread_id);
238 extern int eif_pthread_yield (void);
239 extern EIF_THR_TYPE eif_pthread_self (void);
240 extern int eif_pthread_join (EIF_THR_TYPE thread_id);
241 extern int eif_pthread_set_priority (EIF_THR_TYPE thread_id, rt_uint_ptr priority);
242 extern int eif_pthread_get_priority (EIF_THR_TYPE thread_id, rt_uint_ptr *priority);
243 extern int eif_pthread_is_alive(EIF_THR_TYPE thread_id);
244
245 /* Mutex */
246 extern int eif_pthread_mutex_create (EIF_MUTEX_TYPE **mutex);
247 extern int eif_pthread_mutex_destroy (EIF_MUTEX_TYPE *mutex);
248 extern int eif_pthread_mutex_lock (EIF_MUTEX_TYPE *mutex);
249 extern int eif_pthread_mutex_trylock (EIF_MUTEX_TYPE *mutex);
250 extern int eif_pthread_mutex_unlock (EIF_MUTEX_TYPE *mutex);
251
252 /* Semaphore */
253 extern int eif_pthread_sem_create (EIF_SEM_TYPE ** sem, int shared, unsigned int count);
254 extern int eif_pthread_sem_destroy (EIF_SEM_TYPE * sem);
255 extern int eif_pthread_sem_wait (EIF_SEM_TYPE * sem);
256 extern int eif_pthread_sem_trywait (EIF_SEM_TYPE * sem);
257 extern int eif_pthread_sem_post (EIF_SEM_TYPE * sem);
258
259
260 /* Condition variables */
261 extern int eif_pthread_cond_create (EIF_COND_TYPE ** condvar);
262 extern int eif_pthread_cond_destroy (EIF_COND_TYPE *condvar);
263 extern int eif_pthread_cond_wait (EIF_COND_TYPE *condvar, EIF_MUTEX_TYPE *mutex);
264 extern int eif_pthread_cond_wait_with_timeout (EIF_COND_TYPE *condvar, EIF_MUTEX_TYPE *mutex, rt_uint_ptr timeout);
265 extern int eif_pthread_cond_signal (EIF_COND_TYPE *condvar);
266 extern int eif_pthread_cond_broadcast (EIF_COND_TYPE *condvar);
267
268 /* Read/write lock */
269 extern int eif_pthread_rwlock_create(EIF_RWL_TYPE **rwlp);
270 extern int eif_pthread_rwlock_rdlock (EIF_RWL_TYPE *rwlp);
271 extern int eif_pthread_rwlock_tryrdlock (EIF_RWL_TYPE *rwlp);
272 extern int eif_pthread_rwlock_wrlock (EIF_RWL_TYPE *rwlp);
273 extern int eif_pthread_rwlock_trywrlock (EIF_RWL_TYPE *rwlp);
274 extern int eif_pthread_rwlock_unlock (EIF_RWL_TYPE *rwlp);
275 extern int eif_pthread_rwlock_destroy (EIF_RWL_TYPE * rwlp);
276
277 /* Critical section */
278 extern int eif_pthread_cs_create (EIF_CS_TYPE **section, rt_uint_ptr spin_count);
279 extern int eif_pthread_cs_destroy (EIF_CS_TYPE *section);
280 extern int eif_pthread_cs_lock (EIF_CS_TYPE *section);
281 extern int eif_pthread_cs_trylock (EIF_CS_TYPE *section);
282 extern int eif_pthread_cs_unlock (EIF_CS_TYPE *section);
283
284 #ifdef __cplusplus
285 }
286 #endif
287
288 #endif
289
290 #endif

Properties

Name Value
svn:eol-style native
svn:keywords Author Date ID Revision

  ViewVC Help
Powered by ViewVC 1.1.23