]> git.sesse.net Git - vlc/blob - include/vlc_threads.h
Added a priority for video decoders, for systems with fixed-priority
[vlc] / include / vlc_threads.h
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.12 2002/09/01 21:20:29 massiot Exp $
7  *
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>
12  *
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.
17  * 
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.
22  *
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  *****************************************************************************/
27
28 #include <stdio.h>
29
30 #if defined(GPROF) || defined(DEBUG)
31 #   include <sys/time.h>
32 #endif
33
34 #if defined( PTH_INIT_IN_PTH_H )                                  /* GNU Pth */
35 #   include <pth.h>
36
37 #elif defined( ST_INIT_IN_ST_H )                            /* State threads */
38 #   include <st.h>
39
40 #elif defined( WIN32 )                                          /* Win32 API */
41 #   include <process.h>
42
43 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )  /* pthreads (like Linux & BSD) */
44 #   include <pthread.h>
45 #   ifdef DEBUG
46         /* Needed for pthread_cond_timedwait */
47 #       include <errno.h>
48 #   endif
49     /* This is not prototyped under Linux, though it exists. */
50     int pthread_mutexattr_setkind_np( pthread_mutexattr_t *attr, int kind );
51
52 #elif defined( HAVE_CTHREADS_H )                                  /* GNUMach */
53 #   include <cthreads.h>
54
55 #elif defined( HAVE_KERNEL_SCHEDULER_H )                             /* BeOS */
56 #   include <kernel/OS.h>
57 #   include <kernel/scheduler.h>
58 #   include <byteorder.h>
59
60 #else
61 #   error no threads available on your system !
62
63 #endif
64
65 /*****************************************************************************
66  * Constants
67  *****************************************************************************/
68
69 /* Thread priorities */
70 #ifdef SYS_DARWIN
71 #   define VLC_THREAD_PRIORITY_LOW 0
72 #   define VLC_THREAD_PRIORITY_INPUT 37
73 #   define VLC_THREAD_PRIORITY_AUDIO 38
74 #   define VLC_THREAD_PRIORITY_VIDEO 36
75 #   define VLC_THREAD_PRIORITY_OUTPUT 38
76
77 #elif defined(WIN32)
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
83
84 #else
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
90
91 #endif
92
93 /*****************************************************************************
94  * Type definitions
95  *****************************************************************************/
96
97 #if defined( PTH_INIT_IN_PTH_H )
98 typedef pth_t            vlc_thread_t;
99 typedef struct
100 {
101     pth_mutex_t mutex;
102     vlc_object_t * p_this;
103 } vlc_mutex_t;
104 typedef struct
105 {
106     pth_cond_t cond;
107     vlc_object_t * p_this;
108 } vlc_cond_t;
109
110 #elif defined( ST_INIT_IN_ST_H )
111 typedef st_thread_t      vlc_thread_t;
112 typedef struct
113 {
114     st_mutex_t mutex;
115     vlc_object_t * p_this;
116 } vlc_mutex_t;
117 typedef struct
118 {
119     st_cond_t cond;
120     vlc_object_t * p_this;
121 } vlc_cond_t;
122
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 *);
127
128 typedef struct
129 {
130     /* WinNT/2K/XP implementation */
131     HANDLE              mutex;
132     /* Win95/98/ME implementation */
133     CRITICAL_SECTION    csection;
134
135     vlc_object_t * p_this;
136 } vlc_mutex_t;
137
138 typedef struct
139 {
140     volatile int        i_waiting_threads;
141     /* WinNT/2K/XP implementation */
142     HANDLE              event;
143     SIGNALOBJECTANDWAIT SignalObjectAndWait;
144     /* Win95/98/ME implementation */
145     HANDLE              semaphore;
146     CRITICAL_SECTION    csection;
147     int                 i_win9x_cv;
148
149     vlc_object_t * p_this;
150 } vlc_cond_t;
151
152 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
153 typedef pthread_t       vlc_thread_t;
154 typedef struct
155 {
156     pthread_mutex_t mutex;
157     vlc_object_t * p_this;
158 } vlc_mutex_t;
159 typedef struct
160 {
161     pthread_cond_t cond;
162     vlc_object_t * p_this;
163 } vlc_cond_t;
164
165 #elif defined( HAVE_CTHREADS_H )
166 typedef cthread_t       vlc_thread_t;
167
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*) */
171 typedef struct
172 {
173     spin_lock_t held;
174     spin_lock_t lock;
175     char *name;
176     struct cthread_queue queue;
177
178     vlc_object_t * p_this;
179 } vlc_mutex_t;
180
181 typedef struct
182 {
183     spin_lock_t lock;
184     struct cthread_queue queue;
185     char *name;
186     struct cond_imp *implications;
187
188     vlc_object_t * p_this;
189 } vlc_cond_t;
190
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 */
195
196 typedef thread_id vlc_thread_t;
197
198 typedef struct
199 {
200     int32           init;
201     sem_id          lock;
202
203     vlc_object_t * p_this;
204 } vlc_mutex_t;
205
206 typedef struct
207 {
208     int32           init;
209     thread_id       thread;
210
211     vlc_object_t * p_this;
212 } vlc_cond_t;
213
214 #endif
215