X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=include%2Fvlc_threads.h;h=0065b4dabce78288bed1482de5836efa2f5363ac;hb=f98d6a45b17127f51bda0591af1f3dafe6b1cf44;hp=903deeee5f2d4412405c3f4c1bb5b2ee37c8a104;hpb=88991a5ce9c2603bc5a9be0779353fe08b29e8f9;p=vlc diff --git a/include/vlc_threads.h b/include/vlc_threads.h index 903deeee5f..0065b4dabc 100644 --- a/include/vlc_threads.h +++ b/include/vlc_threads.h @@ -2,8 +2,8 @@ * vlc_threads.h : threads implementation for the VideoLAN client * This header provides portable declarations for mutexes & conditions ***************************************************************************** - * Copyright (C) 1999, 2002 VideoLAN - * $Id: vlc_threads.h,v 1.34 2003/10/25 00:49:13 sam Exp $ + * Copyright (C) 1999, 2002 the VideoLAN team + * $Id$ * * Authors: Jean-Marc Dressler * Samuel Hocevar @@ -14,7 +14,7 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -22,45 +22,37 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include - -#if defined(DEBUG) && defined(HAVE_SYS_TIME_H) -# include +#if !defined( __LIBVLC__ ) + #error You are not libvlc or one of its plugins. You cannot include this file #endif -#if defined( PTH_INIT_IN_PTH_H ) /* GNU Pth */ -# include +#ifndef _VLC_THREADS_H_ +#define _VLC_THREADS_H_ -#elif defined( ST_INIT_IN_ST_H ) /* State threads */ -# include +#include -#elif defined( UNDER_CE ) +#if defined( UNDER_CE ) /* WinCE API */ #elif defined( WIN32 ) # include /* Win32 API */ -#elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) /* pthreads (like Linux & BSD) */ -# include -# ifdef DEBUG - /* Needed for pthread_cond_timedwait */ -# include -# endif - /* This is not prototyped under Linux, though it exists. */ - int pthread_mutexattr_setkind_np( pthread_mutexattr_t *attr, int kind ); - -#elif defined( HAVE_CTHREADS_H ) /* GNUMach */ -# include - #elif defined( HAVE_KERNEL_SCHEDULER_H ) /* BeOS */ # include # include # include -#else -# error no threads available on your system ! +#else /* pthreads (like Linux & BSD) */ +# define LIBVLC_USE_PTHREAD 1 +# define _APPLE_C_SOURCE 1 /* Proper pthread semantics on OSX */ + +# include /* _POSIX_SPIN_LOCKS */ +# include + /* Needed for pthread_cond_timedwait */ +# include +# include #endif @@ -69,18 +61,35 @@ *****************************************************************************/ /* Thread priorities */ -#ifdef SYS_DARWIN +#ifdef __APPLE__ # define VLC_THREAD_PRIORITY_LOW (-47) # define VLC_THREAD_PRIORITY_INPUT 37 # define VLC_THREAD_PRIORITY_AUDIO 37 # define VLC_THREAD_PRIORITY_VIDEO (-47) # define VLC_THREAD_PRIORITY_OUTPUT 37 +# define VLC_THREAD_PRIORITY_HIGHEST 37 + +#elif defined(SYS_BEOS) +# define VLC_THREAD_PRIORITY_LOW 5 +# define VLC_THREAD_PRIORITY_INPUT 10 +# define VLC_THREAD_PRIORITY_AUDIO 10 +# define VLC_THREAD_PRIORITY_VIDEO 5 +# define VLC_THREAD_PRIORITY_OUTPUT 15 +# define VLC_THREAD_PRIORITY_HIGHEST 15 + +#elif defined(LIBVLC_USE_PTHREAD) +# define VLC_THREAD_PRIORITY_LOW 0 +# define VLC_THREAD_PRIORITY_INPUT 20 +# define VLC_THREAD_PRIORITY_AUDIO 10 +# define VLC_THREAD_PRIORITY_VIDEO 0 +# define VLC_THREAD_PRIORITY_OUTPUT 30 +# define VLC_THREAD_PRIORITY_HIGHEST 40 #elif defined(WIN32) || defined(UNDER_CE) /* Define different priorities for WinNT/2K/XP and Win9x/Me */ # define VLC_THREAD_PRIORITY_LOW 0 # define VLC_THREAD_PRIORITY_INPUT \ - (IS_WINNT ? THREAD_PRIORITY_TIME_CRITICAL : 0) + (IS_WINNT ? THREAD_PRIORITY_ABOVE_NORMAL : 0) # define VLC_THREAD_PRIORITY_AUDIO \ (IS_WINNT ? THREAD_PRIORITY_HIGHEST : 0) # define VLC_THREAD_PRIORITY_VIDEO \ @@ -90,19 +99,13 @@ # define VLC_THREAD_PRIORITY_HIGHEST \ (IS_WINNT ? THREAD_PRIORITY_TIME_CRITICAL : 0) -#elif defined(SYS_BEOS) -# define VLC_THREAD_PRIORITY_LOW 5 -# define VLC_THREAD_PRIORITY_INPUT 10 -# define VLC_THREAD_PRIORITY_AUDIO 10 -# define VLC_THREAD_PRIORITY_VIDEO 5 -# define VLC_THREAD_PRIORITY_OUTPUT 15 - #else # define VLC_THREAD_PRIORITY_LOW 0 # define VLC_THREAD_PRIORITY_INPUT 0 # define VLC_THREAD_PRIORITY_AUDIO 0 # define VLC_THREAD_PRIORITY_VIDEO 0 # define VLC_THREAD_PRIORITY_OUTPUT 0 +# define VLC_THREAD_PRIORITY_HIGHEST 0 #endif @@ -110,36 +113,19 @@ * Type definitions *****************************************************************************/ -#if defined( PTH_INIT_IN_PTH_H ) -typedef pth_t vlc_thread_t; +#if defined( WIN32 ) || defined( UNDER_CE ) typedef struct { - pth_mutex_t mutex; - vlc_object_t * p_this; -} vlc_mutex_t; -typedef struct -{ - pth_cond_t cond; - vlc_object_t * p_this; -} vlc_cond_t; + /* thread id */ + DWORD id; + /* + ** handle to created thread, needs be closed to dispose of it + ** even after thread has exited + */ + HANDLE hThread; +} vlc_thread_t; -#elif defined( ST_INIT_IN_ST_H ) -typedef st_thread_t vlc_thread_t; -typedef struct -{ - st_mutex_t mutex; - vlc_object_t * p_this; -} vlc_mutex_t; -typedef struct -{ - st_cond_t cond; - vlc_object_t * p_this; -} vlc_cond_t; - -#elif defined( WIN32 ) || defined( UNDER_CE ) -typedef HANDLE vlc_thread_t; typedef BOOL (WINAPI *SIGNALOBJECTANDWAIT) ( HANDLE, HANDLE, DWORD, BOOL ); -typedef unsigned (__stdcall *PTHREAD_START) (void *); typedef struct { @@ -165,67 +151,57 @@ typedef struct vlc_object_t * p_this; } vlc_cond_t; -#elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) -typedef pthread_t vlc_thread_t; typedef struct { - pthread_mutex_t mutex; - vlc_object_t * p_this; -} vlc_mutex_t; -typedef struct -{ - pthread_cond_t cond; - vlc_object_t * p_this; -} vlc_cond_t; + DWORD handle; +} vlc_threadvar_t; + +#elif defined( HAVE_KERNEL_SCHEDULER_H ) +/* This is the BeOS implementation of the vlc threads, note that the mutex is + * not a real mutex and the cond_var is not like a pthread cond_var but it is + * enough for what we need */ -#elif defined( HAVE_CTHREADS_H ) -typedef cthread_t vlc_thread_t; +typedef thread_id vlc_thread_t; -/* Those structs are the ones defined in /include/cthreads.h but we need - * to handle (&foo) where foo is a (mutex_t) while they handle (foo) where - * foo is a (mutex_t*) */ typedef struct { - spin_lock_t held; - spin_lock_t lock; - char *name; - struct cthread_queue queue; + int32_t init; + sem_id lock; vlc_object_t * p_this; } vlc_mutex_t; typedef struct { - spin_lock_t lock; - struct cthread_queue queue; - char *name; - struct cond_imp *implications; + int32_t init; + thread_id thread; vlc_object_t * p_this; } vlc_cond_t; -#elif defined( HAVE_KERNEL_SCHEDULER_H ) -/* This is the BeOS implementation of the vlc threads, note that the mutex is - * not a real mutex and the cond_var is not like a pthread cond_var but it is - * enough for what wee need */ +typedef struct +{ +} vlc_threadvar_t; -typedef thread_id vlc_thread_t; +#else +typedef pthread_t vlc_thread_t; typedef struct { - int32_t init; - sem_id lock; - + pthread_mutex_t mutex; vlc_object_t * p_this; } vlc_mutex_t; - typedef struct { - int32_t init; - thread_id thread; - + pthread_cond_t cond; vlc_object_t * p_this; } vlc_cond_t; +typedef struct +{ + pthread_key_t handle; +} vlc_threadvar_t; + #endif +#endif /* !_VLC_THREADS_H */