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.37 2004/03/01 12:50:39 gbazin 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 *****************************************************************************/
30 #if defined(DEBUG) && defined(HAVE_SYS_TIME_H)
31 # include <sys/time.h>
34 #if defined( PTH_INIT_IN_PTH_H ) /* GNU Pth */
37 #elif defined( ST_INIT_IN_ST_H ) /* State threads */
40 #elif defined( UNDER_CE )
42 #elif defined( WIN32 )
43 # include <process.h> /* Win32 API */
45 #elif defined( HAVE_KERNEL_SCHEDULER_H ) /* BeOS */
46 # include <kernel/OS.h>
47 # include <kernel/scheduler.h>
48 # include <byteorder.h>
50 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) /* pthreads (like Linux & BSD) */
53 /* Needed for pthread_cond_timedwait */
56 /* This is not prototyped under Linux, though it exists. */
57 int pthread_mutexattr_setkind_np( pthread_mutexattr_t *attr, int kind );
59 #elif defined( HAVE_CTHREADS_H ) /* GNUMach */
60 # include <cthreads.h>
63 # error no threads available on your system !
67 /*****************************************************************************
69 *****************************************************************************/
71 /* Thread priorities */
73 # define VLC_THREAD_PRIORITY_LOW (-47)
74 # define VLC_THREAD_PRIORITY_INPUT 37
75 # define VLC_THREAD_PRIORITY_AUDIO 37
76 # define VLC_THREAD_PRIORITY_VIDEO (-47)
77 # define VLC_THREAD_PRIORITY_OUTPUT 37
79 #elif defined(SYS_BEOS)
80 # define VLC_THREAD_PRIORITY_LOW 5
81 # define VLC_THREAD_PRIORITY_INPUT 10
82 # define VLC_THREAD_PRIORITY_AUDIO 10
83 # define VLC_THREAD_PRIORITY_VIDEO 5
84 # define VLC_THREAD_PRIORITY_OUTPUT 15
86 #elif defined(PTHREAD_COND_T_IN_PTHREAD_H)
87 # define VLC_THREAD_PRIORITY_LOW 0
88 # define VLC_THREAD_PRIORITY_INPUT 20
89 # define VLC_THREAD_PRIORITY_AUDIO 10
90 # define VLC_THREAD_PRIORITY_VIDEO 0
91 # define VLC_THREAD_PRIORITY_OUTPUT 30
93 #elif defined(WIN32) || defined(UNDER_CE)
94 /* Define different priorities for WinNT/2K/XP and Win9x/Me */
95 # define VLC_THREAD_PRIORITY_LOW 0
96 # define VLC_THREAD_PRIORITY_INPUT \
97 (IS_WINNT ? THREAD_PRIORITY_ABOVE_NORMAL : 0)
98 # define VLC_THREAD_PRIORITY_AUDIO \
99 (IS_WINNT ? THREAD_PRIORITY_HIGHEST : 0)
100 # define VLC_THREAD_PRIORITY_VIDEO \
101 (IS_WINNT ? 0 : THREAD_PRIORITY_BELOW_NORMAL )
102 # define VLC_THREAD_PRIORITY_OUTPUT \
103 (IS_WINNT ? THREAD_PRIORITY_ABOVE_NORMAL : 0)
104 # define VLC_THREAD_PRIORITY_HIGHEST \
105 (IS_WINNT ? THREAD_PRIORITY_TIME_CRITICAL : 0)
108 # define VLC_THREAD_PRIORITY_LOW 0
109 # define VLC_THREAD_PRIORITY_INPUT 0
110 # define VLC_THREAD_PRIORITY_AUDIO 0
111 # define VLC_THREAD_PRIORITY_VIDEO 0
112 # define VLC_THREAD_PRIORITY_OUTPUT 0
116 /*****************************************************************************
118 *****************************************************************************/
120 #if defined( PTH_INIT_IN_PTH_H )
121 typedef pth_t vlc_thread_t;
125 vlc_object_t * p_this;
130 vlc_object_t * p_this;
133 #elif defined( ST_INIT_IN_ST_H )
134 typedef st_thread_t vlc_thread_t;
138 vlc_object_t * p_this;
143 vlc_object_t * p_this;
146 #elif defined( WIN32 ) || defined( UNDER_CE )
147 typedef HANDLE vlc_thread_t;
148 typedef BOOL (WINAPI *SIGNALOBJECTANDWAIT) ( HANDLE, HANDLE, DWORD, BOOL );
149 typedef unsigned (__stdcall *PTHREAD_START) (void *);
153 /* WinNT/2K/XP implementation */
155 /* Win95/98/ME implementation */
156 CRITICAL_SECTION csection;
158 vlc_object_t * p_this;
163 volatile int i_waiting_threads;
164 /* WinNT/2K/XP implementation */
166 SIGNALOBJECTANDWAIT SignalObjectAndWait;
167 /* Win95/98/ME implementation */
169 CRITICAL_SECTION csection;
172 vlc_object_t * p_this;
175 #elif defined( HAVE_KERNEL_SCHEDULER_H )
176 /* This is the BeOS implementation of the vlc threads, note that the mutex is
177 * not a real mutex and the cond_var is not like a pthread cond_var but it is
178 * enough for what wee need */
180 typedef thread_id vlc_thread_t;
187 vlc_object_t * p_this;
195 vlc_object_t * p_this;
198 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
199 typedef pthread_t vlc_thread_t;
202 pthread_mutex_t mutex;
203 vlc_object_t * p_this;
208 vlc_object_t * p_this;
211 #elif defined( HAVE_CTHREADS_H )
212 typedef cthread_t vlc_thread_t;
214 /* Those structs are the ones defined in /include/cthreads.h but we need
215 * to handle (&foo) where foo is a (mutex_t) while they handle (foo) where
216 * foo is a (mutex_t*) */
222 struct cthread_queue queue;
224 vlc_object_t * p_this;
230 struct cthread_queue queue;
232 struct cond_imp *implications;
234 vlc_object_t * p_this;