00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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 )
00035 # include <pth.h>
00036
00037 #elif defined( ST_INIT_IN_ST_H )
00038 # include <st.h>
00039
00040 #elif defined( UNDER_CE )
00041
00042 #elif defined( WIN32 )
00043 # include <process.h>
00044
00045 #elif defined( HAVE_KERNEL_SCHEDULER_H )
00046 # include <kernel/OS.h>
00047 # include <kernel/scheduler.h>
00048 # include <byteorder.h>
00049
00050 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
00051 # include <pthread.h>
00052 # ifdef DEBUG
00053
00054 # include <errno.h>
00055 # endif
00056
00057 int pthread_mutexattr_setkind_np( pthread_mutexattr_t *attr, int kind );
00058
00059 #elif defined( HAVE_CTHREADS_H )
00060 # include <cthreads.h>
00061
00062 #else
00063 # error no threads available on your system !
00064
00065 #endif
00066
00067
00068
00069
00070
00071
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
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
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
00158 HANDLE mutex;
00159
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
00169 HANDLE event;
00170 SIGNALOBJECTANDWAIT SignalObjectAndWait;
00171
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
00181
00182
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
00219
00220
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