X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=include%2Fvlc_threads.h;h=9627fc1fc01bd8b22abd8cfebe2bc847cd6127c0;hb=abecc78ae9e26deedc62e34364b8ebcafcea0fdd;hp=fc9123670c79ee034952aba9dd88d23ebb120964;hpb=9e3ab283c258cba17e4ca6730d84f9d00d49b068;p=vlc diff --git a/include/vlc_threads.h b/include/vlc_threads.h index fc9123670c..9627fc1fc0 100644 --- a/include/vlc_threads.h +++ b/include/vlc_threads.h @@ -1,19 +1,20 @@ /***************************************************************************** - * threads.h : threads implementation for the VideoLAN client - * This header provides a portable threads implementation. + * vlc_threads.h : threads implementation for the VideoLAN client + * This header provides portable declarations for mutexes & conditions ***************************************************************************** - * Copyright (C) 1999, 2000 VideoLAN - * $Id: vlc_threads.h,v 1.1 2002/06/01 12:31:58 sam Exp $ + * Copyright (C) 1999, 2002 the VideoLAN team + * $Id$ * * Authors: Jean-Marc Dressler * Samuel Hocevar * Gildas Bazin + * Christophe Massiot * * This program is free software; you can redistribute it and/or modify * 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 @@ -21,12 +22,12 @@ * * 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(GPROF) || defined(DEBUG) +#if defined(DEBUG) && defined(HAVE_SYS_TIME_H) # include #endif @@ -36,10 +37,19 @@ #elif defined( ST_INIT_IN_ST_H ) /* State threads */ # include -#elif defined( WIN32 ) /* Win32 API */ -# include +#elif defined( UNDER_CE ) + /* WinCE API */ +#elif defined( WIN32 ) +# include /* Win32 API */ + +#elif defined( HAVE_KERNEL_SCHEDULER_H ) /* BeOS */ +# include +# include +# include #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) /* pthreads (like Linux & BSD) */ +# define LIBVLC_USE_PTHREAD 1 + # include # ifdef DEBUG /* Needed for pthread_cond_timedwait */ @@ -51,11 +61,6 @@ #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 ! @@ -63,29 +68,56 @@ /***************************************************************************** * Constants - ***************************************************************************** - * These constants are used by all threads in *_CreateThread() and - * *_DestroyThreads() functions. Since those calls are non-blocking, an integer - * value is used as a shared flag to represent the status of the thread. *****************************************************************************/ -/* Void status - this value can be used to make sure no operation is currently - * in progress on the concerned thread in an array of recorded threads */ -#define THREAD_NOP 0 /* nothing happened */ - -/* Creation status */ -#define THREAD_CREATE 10 /* thread is initializing */ -#define THREAD_START 11 /* thread has forked */ -#define THREAD_READY 19 /* thread is ready */ +/* Thread priorities */ +#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(PTHREAD_COND_T_IN_PTHREAD_H) +# 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_ABOVE_NORMAL : 0) +# define VLC_THREAD_PRIORITY_AUDIO \ + (IS_WINNT ? THREAD_PRIORITY_HIGHEST : 0) +# define VLC_THREAD_PRIORITY_VIDEO \ + (IS_WINNT ? 0 : THREAD_PRIORITY_BELOW_NORMAL ) +# define VLC_THREAD_PRIORITY_OUTPUT \ + (IS_WINNT ? THREAD_PRIORITY_ABOVE_NORMAL : 0) +# define VLC_THREAD_PRIORITY_HIGHEST \ + (IS_WINNT ? THREAD_PRIORITY_TIME_CRITICAL : 0) -/* Destructions status */ -#define THREAD_DESTROY 20 /* destruction order has been sent */ -#define THREAD_END 21 /* destruction order has been received */ -#define THREAD_OVER 29 /* thread does not exist any more */ +#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 -/* Error status */ -#define THREAD_ERROR 30 /* an error occured */ -#define THREAD_FATAL 31 /* an fatal error occured - program must end */ +#endif /***************************************************************************** * Type definitions @@ -93,39 +125,97 @@ #if defined( PTH_INIT_IN_PTH_H ) typedef pth_t vlc_thread_t; -typedef pth_mutex_t vlc_mutex_t; -typedef pth_cond_t vlc_cond_t; +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; #elif defined( ST_INIT_IN_ST_H ) -typedef st_thread_t * vlc_thread_t; -typedef st_mutex_t * vlc_mutex_t; -typedef st_cond_t * vlc_cond_t; +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 ) +#elif defined( WIN32 ) || defined( UNDER_CE ) typedef HANDLE vlc_thread_t; +typedef BOOL (WINAPI *SIGNALOBJECTANDWAIT) ( HANDLE, HANDLE, DWORD, BOOL ); +typedef unsigned (WINAPI *PTHREAD_START) (void *); typedef struct { - CRITICAL_SECTION csection; + /* WinNT/2K/XP implementation */ HANDLE mutex; - SIGNALOBJECTANDWAIT SignalObjectAndWait; + /* Win95/98/ME implementation */ + CRITICAL_SECTION csection; + + vlc_object_t * p_this; } vlc_mutex_t; typedef struct { - int i_waiting_threads; - HANDLE signal; + volatile int i_waiting_threads; + /* WinNT/2K/XP implementation */ + HANDLE event; + SIGNALOBJECTANDWAIT SignalObjectAndWait; + /* Win95/98/ME implementation */ + HANDLE semaphore; + CRITICAL_SECTION csection; + int i_win9x_cv; + + vlc_object_t * p_this; } vlc_cond_t; -typedef unsigned (__stdcall *PTHREAD_START) (void *); +#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 thread_id vlc_thread_t; + +typedef struct +{ + int32_t init; + sem_id lock; + + vlc_object_t * p_this; +} vlc_mutex_t; + +typedef struct +{ + int32_t init; + thread_id thread; + + vlc_object_t * p_this; +} vlc_cond_t; #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) -typedef pthread_t vlc_thread_t; -typedef pthread_mutex_t vlc_mutex_t; -typedef pthread_cond_t vlc_cond_t; +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; #elif defined( HAVE_CTHREADS_H ) -typedef cthread_t vlc_thread_t; +typedef cthread_t 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 @@ -136,6 +226,8 @@ typedef struct spin_lock_t lock; char *name; struct cthread_queue queue; + + vlc_object_t * p_this; } vlc_mutex_t; typedef struct @@ -144,25 +236,8 @@ typedef struct struct cthread_queue queue; char *name; struct cond_imp *implications; -} 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 thread_id vlc_thread_t; - -typedef struct -{ - int32 init; - sem_id lock; -} vlc_mutex_t; - -typedef struct -{ - int32 init; - thread_id thread; + vlc_object_t * p_this; } vlc_cond_t; #endif