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
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
32 #ifndef _VLC_THREADS_H_
33 #define _VLC_THREADS_H_
37 #if defined(DEBUG) && defined(HAVE_SYS_TIME_H)
38 # include <sys/time.h>
41 #if defined( UNDER_CE )
43 #elif defined( WIN32 )
44 # include <process.h> /* Win32 API */
46 #elif defined( HAVE_KERNEL_SCHEDULER_H ) /* BeOS */
47 # include <kernel/OS.h>
48 # include <kernel/scheduler.h>
49 # include <byteorder.h>
51 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) /* pthreads (like Linux & BSD) */
52 # define LIBVLC_USE_PTHREAD 1
53 # define _APPLE_C_SOURCE 1 /* Proper pthread semantics on OSX */
55 # include <unistd.h> /* _POSIX_SPIN_LOCKS */
57 /* Needed for pthread_cond_timedwait */
59 /* This is not prototyped under Linux, though it exists. */
60 int pthread_mutexattr_setkind_np( pthread_mutexattr_t *attr, int kind );
62 #elif defined( HAVE_CTHREADS_H ) /* GNUMach */
63 # include <cthreads.h>
66 # error no threads available on your system !
70 /*****************************************************************************
72 *****************************************************************************/
74 /* Thread priorities */
76 # define VLC_THREAD_PRIORITY_LOW (-47)
77 # define VLC_THREAD_PRIORITY_INPUT 37
78 # define VLC_THREAD_PRIORITY_AUDIO 37
79 # define VLC_THREAD_PRIORITY_VIDEO (-47)
80 # define VLC_THREAD_PRIORITY_OUTPUT 37
81 # define VLC_THREAD_PRIORITY_HIGHEST 37
83 #elif defined(SYS_BEOS)
84 # define VLC_THREAD_PRIORITY_LOW 5
85 # define VLC_THREAD_PRIORITY_INPUT 10
86 # define VLC_THREAD_PRIORITY_AUDIO 10
87 # define VLC_THREAD_PRIORITY_VIDEO 5
88 # define VLC_THREAD_PRIORITY_OUTPUT 15
89 # define VLC_THREAD_PRIORITY_HIGHEST 15
91 #elif defined(PTHREAD_COND_T_IN_PTHREAD_H)
92 # define VLC_THREAD_PRIORITY_LOW 0
93 # define VLC_THREAD_PRIORITY_INPUT 20
94 # define VLC_THREAD_PRIORITY_AUDIO 10
95 # define VLC_THREAD_PRIORITY_VIDEO 0
96 # define VLC_THREAD_PRIORITY_OUTPUT 30
97 # define VLC_THREAD_PRIORITY_HIGHEST 40
99 #elif defined(WIN32) || defined(UNDER_CE)
100 /* Define different priorities for WinNT/2K/XP and Win9x/Me */
101 # define VLC_THREAD_PRIORITY_LOW 0
102 # define VLC_THREAD_PRIORITY_INPUT \
103 (IS_WINNT ? THREAD_PRIORITY_ABOVE_NORMAL : 0)
104 # define VLC_THREAD_PRIORITY_AUDIO \
105 (IS_WINNT ? THREAD_PRIORITY_HIGHEST : 0)
106 # define VLC_THREAD_PRIORITY_VIDEO \
107 (IS_WINNT ? 0 : THREAD_PRIORITY_BELOW_NORMAL )
108 # define VLC_THREAD_PRIORITY_OUTPUT \
109 (IS_WINNT ? THREAD_PRIORITY_ABOVE_NORMAL : 0)
110 # define VLC_THREAD_PRIORITY_HIGHEST \
111 (IS_WINNT ? THREAD_PRIORITY_TIME_CRITICAL : 0)
114 # define VLC_THREAD_PRIORITY_LOW 0
115 # define VLC_THREAD_PRIORITY_INPUT 0
116 # define VLC_THREAD_PRIORITY_AUDIO 0
117 # define VLC_THREAD_PRIORITY_VIDEO 0
118 # define VLC_THREAD_PRIORITY_OUTPUT 0
119 # define VLC_THREAD_PRIORITY_HIGHEST 0
123 /*****************************************************************************
125 *****************************************************************************/
127 #if defined( WIN32 ) || defined( UNDER_CE )
133 ** handle to created thread, needs be closed to dispose of it
134 ** even after thread has exited
139 typedef BOOL (WINAPI *SIGNALOBJECTANDWAIT) ( HANDLE, HANDLE, DWORD, BOOL );
143 /* WinNT/2K/XP implementation */
145 /* Win95/98/ME implementation */
146 CRITICAL_SECTION csection;
148 vlc_object_t * p_this;
153 volatile int i_waiting_threads;
154 /* WinNT/2K/XP implementation */
156 SIGNALOBJECTANDWAIT SignalObjectAndWait;
157 /* Win95/98/ME implementation */
159 CRITICAL_SECTION csection;
162 vlc_object_t * p_this;
170 #elif defined( HAVE_KERNEL_SCHEDULER_H )
171 /* This is the BeOS implementation of the vlc threads, note that the mutex is
172 * not a real mutex and the cond_var is not like a pthread cond_var but it is
173 * enough for what we need */
175 typedef thread_id vlc_thread_t;
182 vlc_object_t * p_this;
190 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;
213 pthread_key_t handle;
216 #elif defined( HAVE_CTHREADS_H )
217 typedef cthread_t vlc_thread_t;
219 /* Those structs are the ones defined in /include/cthreads.h but we need
220 * to handle (&foo) where foo is a (mutex_t) while they handle (foo) where
221 * foo is a (mutex_t*) */
227 struct cthread_queue queue;
229 vlc_object_t * p_this;
235 struct cthread_queue queue;
237 struct cond_imp *implications;
239 vlc_object_t * p_this;
244 cthread_key_t handle;