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.21 2003/01/10 17:01:53 titer 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(GPROF) || defined(DEBUG)
31 # ifdef HAVE_SYS_TIME_H
32 # include <sys/time.h>
36 #if defined( PTH_INIT_IN_PTH_H ) /* GNU Pth */
39 #elif defined( ST_INIT_IN_ST_H ) /* State threads */
42 #elif defined( UNDER_CE )
44 #elif defined( WIN32 )
45 # include <process.h> /* Win32 API */
47 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) /* pthreads (like Linux & BSD) */
50 /* Needed for pthread_cond_timedwait */
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>
65 # error no threads available on your system !
69 /*****************************************************************************
71 *****************************************************************************/
73 /* Thread priorities */
75 # define VLC_THREAD_PRIORITY_LOW 31
76 # define VLC_THREAD_PRIORITY_INPUT 35
77 # define VLC_THREAD_PRIORITY_AUDIO 36
78 # define VLC_THREAD_PRIORITY_VIDEO 31
79 # define VLC_THREAD_PRIORITY_OUTPUT 31
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 0
89 # define VLC_THREAD_PRIORITY_OUTPUT \
90 (IS_WINNT ? THREAD_PRIORITY_ABOVE_NORMAL : 0)
91 # define VLC_THREAD_PRIORITY_HIGHEST \
92 (IS_WINNT ? THREAD_PRIORITY_TIME_CRITICAL : 0)
94 #elif defined(SYS_BEOS)
95 # define VLC_THREAD_PRIORITY_LOW 5
96 # define VLC_THREAD_PRIORITY_INPUT 10
97 # define VLC_THREAD_PRIORITY_AUDIO 120
98 # define VLC_THREAD_PRIORITY_VIDEO 15
99 # define VLC_THREAD_PRIORITY_OUTPUT 15
102 # define VLC_THREAD_PRIORITY_LOW 0
103 # define VLC_THREAD_PRIORITY_INPUT 0
104 # define VLC_THREAD_PRIORITY_AUDIO 0
105 # define VLC_THREAD_PRIORITY_VIDEO 0
106 # define VLC_THREAD_PRIORITY_OUTPUT 0
110 /*****************************************************************************
112 *****************************************************************************/
114 #if defined( PTH_INIT_IN_PTH_H )
115 typedef pth_t vlc_thread_t;
119 vlc_object_t * p_this;
124 vlc_object_t * p_this;
127 #elif defined( ST_INIT_IN_ST_H )
128 typedef st_thread_t vlc_thread_t;
132 vlc_object_t * p_this;
137 vlc_object_t * p_this;
140 #elif defined( WIN32 ) || defined( UNDER_CE )
141 typedef HANDLE vlc_thread_t;
142 typedef BOOL (WINAPI *SIGNALOBJECTANDWAIT) ( HANDLE, HANDLE, DWORD, BOOL );
143 typedef unsigned (__stdcall *PTHREAD_START) (void *);
147 /* WinNT/2K/XP implementation */
149 /* Win95/98/ME implementation */
150 CRITICAL_SECTION csection;
152 vlc_object_t * p_this;
157 volatile int i_waiting_threads;
158 /* WinNT/2K/XP implementation */
160 SIGNALOBJECTANDWAIT SignalObjectAndWait;
161 /* Win95/98/ME implementation */
163 CRITICAL_SECTION csection;
166 vlc_object_t * p_this;
169 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
170 typedef pthread_t vlc_thread_t;
173 pthread_mutex_t mutex;
174 vlc_object_t * p_this;
179 vlc_object_t * p_this;
182 #elif defined( HAVE_CTHREADS_H )
183 typedef cthread_t vlc_thread_t;
185 /* Those structs are the ones defined in /include/cthreads.h but we need
186 * to handle (&foo) where foo is a (mutex_t) while they handle (foo) where
187 * foo is a (mutex_t*) */
193 struct cthread_queue queue;
195 vlc_object_t * p_this;
201 struct cthread_queue queue;
203 struct cond_imp *implications;
205 vlc_object_t * p_this;
208 #elif defined( HAVE_KERNEL_SCHEDULER_H )
209 /* This is the BeOS implementation of the vlc threads, note that the mutex is
210 * not a real mutex and the cond_var is not like a pthread cond_var but it is
211 * enough for what wee need */
213 typedef thread_id vlc_thread_t;
220 vlc_object_t * p_this;
228 vlc_object_t * p_this;