Swedish translation update by Daniel Nylander
[vlc.git] / include / vlc_threads.h
blob31b851c62b9adc180e6406f62b7fd21371487a81
1 /*****************************************************************************
2 * vlc_threads.h : threads implementation for the VideoLAN client
3 * This header provides portable declarations for mutexes & conditions
4 *****************************************************************************
5 * Copyright (C) 1999, 2002 the VideoLAN team
6 * $Id$
8 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
9 * Samuel Hocevar <sam@via.ecp.fr>
10 * Gildas Bazin <gbazin@netcourrier.com>
11 * Christophe Massiot <massiot@via.ecp.fr>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 *****************************************************************************/
28 #if !defined( __LIBVLC__ )
29 #error You are not libvlc or one of its plugins. You cannot include this file
30 #endif
32 #ifndef _VLC_THREADS_H_
33 #define _VLC_THREADS_H_
35 #include <stdio.h>
37 #if defined(DEBUG) && defined(HAVE_SYS_TIME_H)
38 # include <sys/time.h>
39 #endif
41 #if defined( PTH_INIT_IN_PTH_H ) /* GNU Pth */
42 # include <pth.h>
44 #elif defined( ST_INIT_IN_ST_H ) /* State threads */
45 # include <st.h>
47 #elif defined( UNDER_CE )
48 /* WinCE API */
49 #elif defined( WIN32 )
50 # include <process.h> /* Win32 API */
52 #elif defined( HAVE_KERNEL_SCHEDULER_H ) /* BeOS */
53 # include <kernel/OS.h>
54 # include <kernel/scheduler.h>
55 # include <byteorder.h>
57 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) /* pthreads (like Linux & BSD) */
58 # define LIBVLC_USE_PTHREAD 1
59 # define _APPLE_C_SOURCE 1 /* Proper pthread semantics on OSX */
61 # include <pthread.h>
62 /* Needed for pthread_cond_timedwait */
63 # include <errno.h>
64 /* This is not prototyped under Linux, though it exists. */
65 int pthread_mutexattr_setkind_np( pthread_mutexattr_t *attr, int kind );
67 #elif defined( HAVE_CTHREADS_H ) /* GNUMach */
68 # include <cthreads.h>
70 #else
71 # error no threads available on your system !
73 #endif
75 /*****************************************************************************
76 * Constants
77 *****************************************************************************/
79 /* Thread priorities */
80 #ifdef __APPLE__
81 # define VLC_THREAD_PRIORITY_LOW (-47)
82 # define VLC_THREAD_PRIORITY_INPUT 37
83 # define VLC_THREAD_PRIORITY_AUDIO 37
84 # define VLC_THREAD_PRIORITY_VIDEO (-47)
85 # define VLC_THREAD_PRIORITY_OUTPUT 37
86 # define VLC_THREAD_PRIORITY_HIGHEST 37
88 #elif defined(SYS_BEOS)
89 # define VLC_THREAD_PRIORITY_LOW 5
90 # define VLC_THREAD_PRIORITY_INPUT 10
91 # define VLC_THREAD_PRIORITY_AUDIO 10
92 # define VLC_THREAD_PRIORITY_VIDEO 5
93 # define VLC_THREAD_PRIORITY_OUTPUT 15
94 # define VLC_THREAD_PRIORITY_HIGHEST 15
96 #elif defined(PTHREAD_COND_T_IN_PTHREAD_H)
97 # define VLC_THREAD_PRIORITY_LOW 0
98 # define VLC_THREAD_PRIORITY_INPUT 20
99 # define VLC_THREAD_PRIORITY_AUDIO 10
100 # define VLC_THREAD_PRIORITY_VIDEO 0
101 # define VLC_THREAD_PRIORITY_OUTPUT 30
102 # define VLC_THREAD_PRIORITY_HIGHEST 40
104 #elif defined(WIN32) || defined(UNDER_CE)
105 /* Define different priorities for WinNT/2K/XP and Win9x/Me */
106 # define VLC_THREAD_PRIORITY_LOW 0
107 # define VLC_THREAD_PRIORITY_INPUT \
108 (IS_WINNT ? THREAD_PRIORITY_ABOVE_NORMAL : 0)
109 # define VLC_THREAD_PRIORITY_AUDIO \
110 (IS_WINNT ? THREAD_PRIORITY_HIGHEST : 0)
111 # define VLC_THREAD_PRIORITY_VIDEO \
112 (IS_WINNT ? 0 : THREAD_PRIORITY_BELOW_NORMAL )
113 # define VLC_THREAD_PRIORITY_OUTPUT \
114 (IS_WINNT ? THREAD_PRIORITY_ABOVE_NORMAL : 0)
115 # define VLC_THREAD_PRIORITY_HIGHEST \
116 (IS_WINNT ? THREAD_PRIORITY_TIME_CRITICAL : 0)
118 #else
119 # define VLC_THREAD_PRIORITY_LOW 0
120 # define VLC_THREAD_PRIORITY_INPUT 0
121 # define VLC_THREAD_PRIORITY_AUDIO 0
122 # define VLC_THREAD_PRIORITY_VIDEO 0
123 # define VLC_THREAD_PRIORITY_OUTPUT 0
124 # define VLC_THREAD_PRIORITY_HIGHEST 0
126 #endif
128 /*****************************************************************************
129 * Type definitions
130 *****************************************************************************/
132 #if defined( PTH_INIT_IN_PTH_H )
133 typedef pth_t vlc_thread_t;
134 typedef struct
136 pth_mutex_t mutex;
137 vlc_object_t * p_this;
138 } vlc_mutex_t;
139 typedef struct
141 pth_cond_t cond;
142 vlc_object_t * p_this;
143 } vlc_cond_t;
144 typedef struct
146 int handle;
147 } vlc_threadvar_t;
149 #elif defined( ST_INIT_IN_ST_H )
150 typedef st_thread_t vlc_thread_t;
151 typedef struct
153 st_mutex_t mutex;
154 vlc_object_t * p_this;
155 } vlc_mutex_t;
156 typedef struct
158 st_cond_t cond;
159 vlc_object_t * p_this;
160 } vlc_cond_t;
161 typedef struct
163 int handle;
164 } vlc_threadvar_t;
166 #elif defined( WIN32 ) || defined( UNDER_CE )
167 typedef struct
169 /* thread id */
170 DWORD id;
172 ** handle to created thread, needs be closed to dispose of it
173 ** even after thread has exited
175 HANDLE hThread;
176 } vlc_thread_t;
178 typedef BOOL (WINAPI *SIGNALOBJECTANDWAIT) ( HANDLE, HANDLE, DWORD, BOOL );
180 typedef struct
182 /* WinNT/2K/XP implementation */
183 HANDLE mutex;
184 /* Win95/98/ME implementation */
185 CRITICAL_SECTION csection;
187 vlc_object_t * p_this;
188 } vlc_mutex_t;
190 typedef struct
192 volatile int i_waiting_threads;
193 /* WinNT/2K/XP implementation */
194 HANDLE event;
195 SIGNALOBJECTANDWAIT SignalObjectAndWait;
196 /* Win95/98/ME implementation */
197 HANDLE semaphore;
198 CRITICAL_SECTION csection;
199 int i_win9x_cv;
201 vlc_object_t * p_this;
202 } vlc_cond_t;
204 typedef struct
206 DWORD handle;
207 } vlc_threadvar_t;
209 #elif defined( HAVE_KERNEL_SCHEDULER_H )
210 /* This is the BeOS implementation of the vlc threads, note that the mutex is
211 * not a real mutex and the cond_var is not like a pthread cond_var but it is
212 * enough for what we need */
214 typedef thread_id vlc_thread_t;
216 typedef struct
218 int32_t init;
219 sem_id lock;
221 vlc_object_t * p_this;
222 } vlc_mutex_t;
224 typedef struct
226 int32_t init;
227 thread_id thread;
229 vlc_object_t * p_this;
230 } vlc_cond_t;
232 typedef struct
234 } vlc_threadvar_t;
237 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
238 typedef pthread_t vlc_thread_t;
239 typedef struct
241 pthread_mutex_t mutex;
242 vlc_object_t * p_this;
243 } vlc_mutex_t;
244 typedef struct
246 pthread_cond_t cond;
247 vlc_object_t * p_this;
248 } vlc_cond_t;
250 typedef struct
252 pthread_key_t handle;
253 } vlc_threadvar_t;
255 #elif defined( HAVE_CTHREADS_H )
256 typedef cthread_t vlc_thread_t;
258 /* Those structs are the ones defined in /include/cthreads.h but we need
259 * to handle (&foo) where foo is a (mutex_t) while they handle (foo) where
260 * foo is a (mutex_t*) */
261 typedef struct
263 spin_lock_t held;
264 spin_lock_t lock;
265 char *name;
266 struct cthread_queue queue;
268 vlc_object_t * p_this;
269 } vlc_mutex_t;
271 typedef struct
273 spin_lock_t lock;
274 struct cthread_queue queue;
275 char *name;
276 struct cond_imp *implications;
278 vlc_object_t * p_this;
279 } vlc_cond_t;
281 typedef struct
283 cthread_key_t handle;
284 } vlc_threadvar_t;
286 #endif
288 #endif