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.14 2002/10/08 22:48:25 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 *****************************************************************************/
30 #if defined(GPROF) || defined(DEBUG)
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( WIN32 ) /* Win32 API */
43 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) /* pthreads (like Linux & BSD) */
46 /* Needed for pthread_cond_timedwait */
49 /* This is not prototyped under Linux, though it exists. */
50 int pthread_mutexattr_setkind_np( pthread_mutexattr_t *attr, int kind );
52 #elif defined( HAVE_CTHREADS_H ) /* GNUMach */
53 # include <cthreads.h>
55 #elif defined( HAVE_KERNEL_SCHEDULER_H ) /* BeOS */
56 # include <kernel/OS.h>
57 # include <kernel/scheduler.h>
58 # include <byteorder.h>
61 # error no threads available on your system !
65 /*****************************************************************************
67 *****************************************************************************/
69 /* Thread priorities */
71 # define VLC_THREAD_PRIORITY_LOW 31
72 # define VLC_THREAD_PRIORITY_INPUT 37
73 # define VLC_THREAD_PRIORITY_AUDIO 38
74 # define VLC_THREAD_PRIORITY_VIDEO 31
75 # define VLC_THREAD_PRIORITY_OUTPUT 38
78 # define VLC_THREAD_PRIORITY_LOW 0
79 # define VLC_THREAD_PRIORITY_INPUT THREAD_PRIORITY_ABOVE_NORMAL
80 # define VLC_THREAD_PRIORITY_AUDIO THREAD_PRIORITY_ABOVE_NORMAL
81 # define VLC_THREAD_PRIORITY_VIDEO 0
82 # define VLC_THREAD_PRIORITY_OUTPUT THREAD_PRIORITY_ABOVE_NORMAL
85 # define VLC_THREAD_PRIORITY_LOW 0
86 # define VLC_THREAD_PRIORITY_INPUT 0
87 # define VLC_THREAD_PRIORITY_AUDIO 0
88 # define VLC_THREAD_PRIORITY_VIDEO 0
89 # define VLC_THREAD_PRIORITY_OUTPUT 0
93 /*****************************************************************************
95 *****************************************************************************/
97 #if defined( PTH_INIT_IN_PTH_H )
98 typedef pth_t vlc_thread_t;
102 vlc_object_t * p_this;
107 vlc_object_t * p_this;
110 #elif defined( ST_INIT_IN_ST_H )
111 typedef st_thread_t vlc_thread_t;
115 vlc_object_t * p_this;
120 vlc_object_t * p_this;
123 #elif defined( WIN32 )
124 typedef HANDLE vlc_thread_t;
125 typedef BOOL (WINAPI *SIGNALOBJECTANDWAIT) ( HANDLE, HANDLE, DWORD, BOOL );
126 typedef unsigned (__stdcall *PTHREAD_START) (void *);
130 /* WinNT/2K/XP implementation */
132 /* Win95/98/ME implementation */
133 CRITICAL_SECTION csection;
135 vlc_object_t * p_this;
140 volatile int i_waiting_threads;
141 /* WinNT/2K/XP implementation */
143 SIGNALOBJECTANDWAIT SignalObjectAndWait;
144 /* Win95/98/ME implementation */
146 CRITICAL_SECTION csection;
149 vlc_object_t * p_this;
152 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
153 typedef pthread_t vlc_thread_t;
156 pthread_mutex_t mutex;
157 vlc_object_t * p_this;
162 vlc_object_t * p_this;
165 #elif defined( HAVE_CTHREADS_H )
166 typedef cthread_t vlc_thread_t;
168 /* Those structs are the ones defined in /include/cthreads.h but we need
169 * to handle (&foo) where foo is a (mutex_t) while they handle (foo) where
170 * foo is a (mutex_t*) */
176 struct cthread_queue queue;
178 vlc_object_t * p_this;
184 struct cthread_queue queue;
186 struct cond_imp *implications;
188 vlc_object_t * p_this;
191 #elif defined( HAVE_KERNEL_SCHEDULER_H )
192 /* This is the BeOS implementation of the vlc threads, note that the mutex is
193 * not a real mutex and the cond_var is not like a pthread cond_var but it is
194 * enough for what wee need */
196 typedef thread_id vlc_thread_t;
203 vlc_object_t * p_this;
211 vlc_object_t * p_this;