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.17 2002/11/10 18:04:22 sam 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( WIN32 )
43 # if defined( UNDER_CE )
46 # include <process.h> /* Win32 API */
49 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) /* pthreads (like Linux & BSD) */
52 /* Needed for pthread_cond_timedwait */
55 /* This is not prototyped under Linux, though it exists. */
56 int pthread_mutexattr_setkind_np( pthread_mutexattr_t *attr, int kind );
58 #elif defined( HAVE_CTHREADS_H ) /* GNUMach */
59 # include <cthreads.h>
61 #elif defined( HAVE_KERNEL_SCHEDULER_H ) /* BeOS */
62 # include <kernel/OS.h>
63 # include <kernel/scheduler.h>
64 # include <byteorder.h>
67 # error no threads available on your system !
71 /*****************************************************************************
73 *****************************************************************************/
75 /* Thread priorities */
77 # define VLC_THREAD_PRIORITY_LOW 31
78 # define VLC_THREAD_PRIORITY_INPUT 37
79 # define VLC_THREAD_PRIORITY_AUDIO 38
80 # define VLC_THREAD_PRIORITY_VIDEO 31
81 # define VLC_THREAD_PRIORITY_OUTPUT 31
84 # define VLC_THREAD_PRIORITY_LOW 0
85 # define VLC_THREAD_PRIORITY_INPUT THREAD_PRIORITY_TIME_CRITICAL
86 # define VLC_THREAD_PRIORITY_AUDIO THREAD_PRIORITY_HIGHEST
87 # define VLC_THREAD_PRIORITY_VIDEO 0
88 # define VLC_THREAD_PRIORITY_OUTPUT THREAD_PRIORITY_ABOVE_NORMAL
91 # define VLC_THREAD_PRIORITY_LOW 0
92 # define VLC_THREAD_PRIORITY_INPUT 0
93 # define VLC_THREAD_PRIORITY_AUDIO 0
94 # define VLC_THREAD_PRIORITY_VIDEO 0
95 # define VLC_THREAD_PRIORITY_OUTPUT 0
99 /*****************************************************************************
101 *****************************************************************************/
103 #if defined( PTH_INIT_IN_PTH_H )
104 typedef pth_t vlc_thread_t;
108 vlc_object_t * p_this;
113 vlc_object_t * p_this;
116 #elif defined( ST_INIT_IN_ST_H )
117 typedef st_thread_t vlc_thread_t;
121 vlc_object_t * p_this;
126 vlc_object_t * p_this;
129 #elif defined( WIN32 )
130 typedef HANDLE vlc_thread_t;
131 typedef BOOL (WINAPI *SIGNALOBJECTANDWAIT) ( HANDLE, HANDLE, DWORD, BOOL );
132 typedef unsigned (__stdcall *PTHREAD_START) (void *);
136 /* WinNT/2K/XP implementation */
138 /* Win95/98/ME implementation */
139 CRITICAL_SECTION csection;
141 vlc_object_t * p_this;
146 volatile int i_waiting_threads;
147 /* WinNT/2K/XP implementation */
149 SIGNALOBJECTANDWAIT SignalObjectAndWait;
150 /* Win95/98/ME implementation */
152 CRITICAL_SECTION csection;
155 vlc_object_t * p_this;
158 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
159 typedef pthread_t vlc_thread_t;
162 pthread_mutex_t mutex;
163 vlc_object_t * p_this;
168 vlc_object_t * p_this;
171 #elif defined( HAVE_CTHREADS_H )
172 typedef cthread_t vlc_thread_t;
174 /* Those structs are the ones defined in /include/cthreads.h but we need
175 * to handle (&foo) where foo is a (mutex_t) while they handle (foo) where
176 * foo is a (mutex_t*) */
182 struct cthread_queue queue;
184 vlc_object_t * p_this;
190 struct cthread_queue queue;
192 struct cond_imp *implications;
194 vlc_object_t * p_this;
197 #elif defined( HAVE_KERNEL_SCHEDULER_H )
198 /* This is the BeOS implementation of the vlc threads, note that the mutex is
199 * not a real mutex and the cond_var is not like a pthread cond_var but it is
200 * enough for what wee need */
202 typedef thread_id vlc_thread_t;
209 vlc_object_t * p_this;
217 vlc_object_t * p_this;