* ./NEWS: a few updates (translations, mozilla plugin).
[vlc.git] / include / vlc_threads.h
blobdc7c4772c7862cbe153c636336dacebf019b9f02
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 VideoLAN
6 * $Id: vlc_threads.h,v 1.25 2003/01/30 00:39:41 massiot Exp $
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
26 *****************************************************************************/
28 #include <stdio.h>
30 #if defined(GPROF) || defined(DEBUG)
31 # ifdef HAVE_SYS_TIME_H
32 # include <sys/time.h>
33 # endif
34 #endif
36 #if defined( PTH_INIT_IN_PTH_H ) /* GNU Pth */
37 # include <pth.h>
39 #elif defined( ST_INIT_IN_ST_H ) /* State threads */
40 # include <st.h>
42 #elif defined( UNDER_CE )
43 /* WinCE API */
44 #elif defined( WIN32 )
45 # include <process.h> /* Win32 API */
47 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) /* pthreads (like Linux & BSD) */
48 # include <pthread.h>
49 # ifdef DEBUG
50 /* Needed for pthread_cond_timedwait */
51 # include <errno.h>
52 # endif
53 /* This is not prototyped under Linux, though it exists. */
54 int pthread_mutexattr_setkind_np( pthread_mutexattr_t *attr, int kind );
56 #elif defined( HAVE_CTHREADS_H ) /* GNUMach */
57 # include <cthreads.h>
59 #elif defined( HAVE_KERNEL_SCHEDULER_H ) /* BeOS */
60 # include <kernel/OS.h>
61 # include <kernel/scheduler.h>
62 # include <byteorder.h>
64 #else
65 # error no threads available on your system !
67 #endif
69 /*****************************************************************************
70 * Constants
71 *****************************************************************************/
73 /* Thread priorities */
74 #ifdef SYS_DARWIN
75 # define VLC_THREAD_PRIORITY_LOW 32
76 # define VLC_THREAD_PRIORITY_INPUT 36
77 # define VLC_THREAD_PRIORITY_AUDIO 37
78 # define VLC_THREAD_PRIORITY_VIDEO 33
79 # define VLC_THREAD_PRIORITY_OUTPUT 34
81 #elif defined(WIN32) || defined(UNDER_CE)
82 /* Define different priorities for WinNT/2K/XP and Win9x/Me */
83 # define VLC_THREAD_PRIORITY_LOW 0
84 # define VLC_THREAD_PRIORITY_INPUT \
85 (IS_WINNT ? THREAD_PRIORITY_TIME_CRITICAL : 0)
86 # define VLC_THREAD_PRIORITY_AUDIO \
87 (IS_WINNT ? THREAD_PRIORITY_HIGHEST : 0)
88 # define VLC_THREAD_PRIORITY_VIDEO \
89 (IS_WINNT ? 0 : THREAD_PRIORITY_BELOW_NORMAL )
90 # define VLC_THREAD_PRIORITY_OUTPUT \
91 (IS_WINNT ? THREAD_PRIORITY_ABOVE_NORMAL : 0)
92 # define VLC_THREAD_PRIORITY_HIGHEST \
93 (IS_WINNT ? THREAD_PRIORITY_TIME_CRITICAL : 0)
95 #elif defined(SYS_BEOS)
96 # define VLC_THREAD_PRIORITY_LOW 5
97 # define VLC_THREAD_PRIORITY_INPUT 10
98 # define VLC_THREAD_PRIORITY_AUDIO 100
99 # define VLC_THREAD_PRIORITY_VIDEO 15
100 # define VLC_THREAD_PRIORITY_OUTPUT 15
102 #else
103 # define VLC_THREAD_PRIORITY_LOW 0
104 # define VLC_THREAD_PRIORITY_INPUT 0
105 # define VLC_THREAD_PRIORITY_AUDIO 0
106 # define VLC_THREAD_PRIORITY_VIDEO 0
107 # define VLC_THREAD_PRIORITY_OUTPUT 0
109 #endif
111 /*****************************************************************************
112 * Type definitions
113 *****************************************************************************/
115 #if defined( PTH_INIT_IN_PTH_H )
116 typedef pth_t vlc_thread_t;
117 typedef struct
119 pth_mutex_t mutex;
120 vlc_object_t * p_this;
121 } vlc_mutex_t;
122 typedef struct
124 pth_cond_t cond;
125 vlc_object_t * p_this;
126 } vlc_cond_t;
128 #elif defined( ST_INIT_IN_ST_H )
129 typedef st_thread_t vlc_thread_t;
130 typedef struct
132 st_mutex_t mutex;
133 vlc_object_t * p_this;
134 } vlc_mutex_t;
135 typedef struct
137 st_cond_t cond;
138 vlc_object_t * p_this;
139 } vlc_cond_t;
141 #elif defined( WIN32 ) || defined( UNDER_CE )
142 typedef HANDLE vlc_thread_t;
143 typedef BOOL (WINAPI *SIGNALOBJECTANDWAIT) ( HANDLE, HANDLE, DWORD, BOOL );
144 typedef unsigned (__stdcall *PTHREAD_START) (void *);
146 typedef struct
148 /* WinNT/2K/XP implementation */
149 HANDLE mutex;
150 /* Win95/98/ME implementation */
151 CRITICAL_SECTION csection;
153 vlc_object_t * p_this;
154 } vlc_mutex_t;
156 typedef struct
158 volatile int i_waiting_threads;
159 /* WinNT/2K/XP implementation */
160 HANDLE event;
161 SIGNALOBJECTANDWAIT SignalObjectAndWait;
162 /* Win95/98/ME implementation */
163 HANDLE semaphore;
164 CRITICAL_SECTION csection;
165 int i_win9x_cv;
167 vlc_object_t * p_this;
168 } vlc_cond_t;
170 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
171 typedef pthread_t vlc_thread_t;
172 typedef struct
174 pthread_mutex_t mutex;
175 vlc_object_t * p_this;
176 } vlc_mutex_t;
177 typedef struct
179 pthread_cond_t cond;
180 vlc_object_t * p_this;
181 } vlc_cond_t;
183 #elif defined( HAVE_CTHREADS_H )
184 typedef cthread_t vlc_thread_t;
186 /* Those structs are the ones defined in /include/cthreads.h but we need
187 * to handle (&foo) where foo is a (mutex_t) while they handle (foo) where
188 * foo is a (mutex_t*) */
189 typedef struct
191 spin_lock_t held;
192 spin_lock_t lock;
193 char *name;
194 struct cthread_queue queue;
196 vlc_object_t * p_this;
197 } vlc_mutex_t;
199 typedef struct
201 spin_lock_t lock;
202 struct cthread_queue queue;
203 char *name;
204 struct cond_imp *implications;
206 vlc_object_t * p_this;
207 } vlc_cond_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 wee need */
214 typedef thread_id vlc_thread_t;
216 typedef struct
218 int32 init;
219 sem_id lock;
221 vlc_object_t * p_this;
222 } vlc_mutex_t;
224 typedef struct
226 int32 init;
227 thread_id thread;
229 vlc_object_t * p_this;
230 } vlc_cond_t;
232 #endif