Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

vlc_threads.h

00001 /*****************************************************************************
00002  * vlc_threads.h : threads implementation for the VideoLAN client
00003  * This header provides portable declarations for mutexes & conditions
00004  *****************************************************************************
00005  * Copyright (C) 1999, 2002 the VideoLAN team
00006  * $Id: vlc_threads.h 11664 2005-07-09 06:17:09Z courmisch $
00007  *
00008  * Authors: Jean-Marc Dressler <[email protected]>
00009  *          Samuel Hocevar <[email protected]>
00010  *          Gildas Bazin <[email protected]>
00011  *          Christophe Massiot <[email protected]>
00012  *
00013  * This program is free software; you can redistribute it and/or modify
00014  * it under the terms of the GNU General Public License as published by
00015  * the Free Software Foundation; either version 2 of the License, or
00016  * (at your option) any later version.
00017  *
00018  * This program is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with this program; if not, write to the Free Software
00025  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00026  *****************************************************************************/
00027 
00028 #include <stdio.h>
00029 
00030 #if defined(DEBUG) && defined(HAVE_SYS_TIME_H)
00031 #   include <sys/time.h>
00032 #endif
00033 
00034 #if defined( PTH_INIT_IN_PTH_H )                                  /* GNU Pth */
00035 #   include <pth.h>
00036 
00037 #elif defined( ST_INIT_IN_ST_H )                            /* State threads */
00038 #   include <st.h>
00039 
00040 #elif defined( UNDER_CE )
00041                                                                 /* WinCE API */
00042 #elif defined( WIN32 )
00043 #   include <process.h>                                         /* Win32 API */
00044 
00045 #elif defined( HAVE_KERNEL_SCHEDULER_H )                             /* BeOS */
00046 #   include <kernel/OS.h>
00047 #   include <kernel/scheduler.h>
00048 #   include <byteorder.h>
00049 
00050 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )  /* pthreads (like Linux & BSD) */
00051 #   include <pthread.h>
00052 #   ifdef DEBUG
00053         /* Needed for pthread_cond_timedwait */
00054 #       include <errno.h>
00055 #   endif
00056     /* This is not prototyped under Linux, though it exists. */
00057     int pthread_mutexattr_setkind_np( pthread_mutexattr_t *attr, int kind );
00058 
00059 #elif defined( HAVE_CTHREADS_H )                                  /* GNUMach */
00060 #   include <cthreads.h>
00061 
00062 #else
00063 #   error no threads available on your system !
00064 
00065 #endif
00066 
00067 /*****************************************************************************
00068  * Constants
00069  *****************************************************************************/
00070 
00071 /* Thread priorities */
00072 #ifdef SYS_DARWIN
00073 #   define VLC_THREAD_PRIORITY_LOW (-47)
00074 #   define VLC_THREAD_PRIORITY_INPUT 37
00075 #   define VLC_THREAD_PRIORITY_AUDIO 37
00076 #   define VLC_THREAD_PRIORITY_VIDEO (-47)
00077 #   define VLC_THREAD_PRIORITY_OUTPUT 37
00078 #   define VLC_THREAD_PRIORITY_HIGHEST 37
00079 
00080 #elif defined(SYS_BEOS)
00081 #   define VLC_THREAD_PRIORITY_LOW 5
00082 #   define VLC_THREAD_PRIORITY_INPUT 10
00083 #   define VLC_THREAD_PRIORITY_AUDIO 10
00084 #   define VLC_THREAD_PRIORITY_VIDEO 5
00085 #   define VLC_THREAD_PRIORITY_OUTPUT 15
00086 #   define VLC_THREAD_PRIORITY_HIGHEST 15
00087 
00088 #elif defined(PTHREAD_COND_T_IN_PTHREAD_H)
00089 #   define VLC_THREAD_PRIORITY_LOW 0
00090 #   define VLC_THREAD_PRIORITY_INPUT 20
00091 #   define VLC_THREAD_PRIORITY_AUDIO 10
00092 #   define VLC_THREAD_PRIORITY_VIDEO 0
00093 #   define VLC_THREAD_PRIORITY_OUTPUT 30
00094 #   define VLC_THREAD_PRIORITY_HIGHEST 40
00095 
00096 #elif defined(WIN32) || defined(UNDER_CE)
00097 /* Define different priorities for WinNT/2K/XP and Win9x/Me */
00098 #   define VLC_THREAD_PRIORITY_LOW 0
00099 #   define VLC_THREAD_PRIORITY_INPUT \
00100         (IS_WINNT ? THREAD_PRIORITY_ABOVE_NORMAL : 0)
00101 #   define VLC_THREAD_PRIORITY_AUDIO \
00102         (IS_WINNT ? THREAD_PRIORITY_HIGHEST : 0)
00103 #   define VLC_THREAD_PRIORITY_VIDEO \
00104         (IS_WINNT ? 0 : THREAD_PRIORITY_BELOW_NORMAL )
00105 #   define VLC_THREAD_PRIORITY_OUTPUT \
00106         (IS_WINNT ? THREAD_PRIORITY_ABOVE_NORMAL : 0)
00107 #   define VLC_THREAD_PRIORITY_HIGHEST \
00108         (IS_WINNT ? THREAD_PRIORITY_TIME_CRITICAL : 0)
00109 
00110 #else
00111 #   define VLC_THREAD_PRIORITY_LOW 0
00112 #   define VLC_THREAD_PRIORITY_INPUT 0
00113 #   define VLC_THREAD_PRIORITY_AUDIO 0
00114 #   define VLC_THREAD_PRIORITY_VIDEO 0
00115 #   define VLC_THREAD_PRIORITY_OUTPUT 0
00116 #   define VLC_THREAD_PRIORITY_HIGHEST 0
00117 
00118 #endif
00119 
00120 /*****************************************************************************
00121  * Type definitions
00122  *****************************************************************************/
00123 
00124 #if defined( PTH_INIT_IN_PTH_H )
00125 typedef pth_t            vlc_thread_t;
00126 typedef struct
00127 {
00128     pth_mutex_t mutex;
00129     vlc_object_t * p_this;
00130 } vlc_mutex_t;
00131 typedef struct
00132 {
00133     pth_cond_t cond;
00134     vlc_object_t * p_this;
00135 } vlc_cond_t;
00136 
00137 #elif defined( ST_INIT_IN_ST_H )
00138 typedef st_thread_t      vlc_thread_t;
00139 typedef struct
00140 {
00141     st_mutex_t mutex;
00142     vlc_object_t * p_this;
00143 } vlc_mutex_t;
00144 typedef struct
00145 {
00146     st_cond_t cond;
00147     vlc_object_t * p_this;
00148 } vlc_cond_t;
00149 
00150 #elif defined( WIN32 ) || defined( UNDER_CE )
00151 typedef HANDLE vlc_thread_t;
00152 typedef BOOL (WINAPI *SIGNALOBJECTANDWAIT) ( HANDLE, HANDLE, DWORD, BOOL );
00153 typedef unsigned (WINAPI *PTHREAD_START) (void *);
00154 
00155 typedef struct
00156 {
00157     /* WinNT/2K/XP implementation */
00158     HANDLE              mutex;
00159     /* Win95/98/ME implementation */
00160     CRITICAL_SECTION    csection;
00161 
00162     vlc_object_t * p_this;
00163 } vlc_mutex_t;
00164 
00165 typedef struct
00166 {
00167     volatile int        i_waiting_threads;
00168     /* WinNT/2K/XP implementation */
00169     HANDLE              event;
00170     SIGNALOBJECTANDWAIT SignalObjectAndWait;
00171     /* Win95/98/ME implementation */
00172     HANDLE              semaphore;
00173     CRITICAL_SECTION    csection;
00174     int                 i_win9x_cv;
00175 
00176     vlc_object_t * p_this;
00177 } vlc_cond_t;
00178 
00179 #elif defined( HAVE_KERNEL_SCHEDULER_H )
00180 /* This is the BeOS implementation of the vlc threads, note that the mutex is
00181  * not a real mutex and the cond_var is not like a pthread cond_var but it is
00182  * enough for what wee need */
00183 
00184 typedef thread_id vlc_thread_t;
00185 
00186 typedef struct
00187 {
00188     int32_t         init;
00189     sem_id          lock;
00190 
00191     vlc_object_t * p_this;
00192 } vlc_mutex_t;
00193 
00194 typedef struct
00195 {
00196     int32_t         init;
00197     thread_id       thread;
00198 
00199     vlc_object_t * p_this;
00200 } vlc_cond_t;
00201 
00202 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
00203 typedef pthread_t       vlc_thread_t;
00204 typedef struct
00205 {
00206     pthread_mutex_t mutex;
00207     vlc_object_t * p_this;
00208 } vlc_mutex_t;
00209 typedef struct
00210 {
00211     pthread_cond_t cond;
00212     vlc_object_t * p_this;
00213 } vlc_cond_t;
00214 
00215 #elif defined( HAVE_CTHREADS_H )
00216 typedef cthread_t       vlc_thread_t;
00217 
00218 /* Those structs are the ones defined in /include/cthreads.h but we need
00219  * to handle (&foo) where foo is a (mutex_t) while they handle (foo) where
00220  * foo is a (mutex_t*) */
00221 typedef struct
00222 {
00223     spin_lock_t held;
00224     spin_lock_t lock;
00225     char *name;
00226     struct cthread_queue queue;
00227 
00228     vlc_object_t * p_this;
00229 } vlc_mutex_t;
00230 
00231 typedef struct
00232 {
00233     spin_lock_t lock;
00234     struct cthread_queue queue;
00235     char *name;
00236     struct cond_imp *implications;
00237 
00238     vlc_object_t * p_this;
00239 } vlc_cond_t;
00240 
00241 #endif
00242 

Generated on Tue Dec 20 10:14:19 2005 for vlc-0.8.4a by  doxygen 1.4.2