Tell fribidi we are not compiling a dll
[vlc/vlc-skelet.git] / include / vlc_threads.h
blobd10ca4d24ae7ef79ab92f3941e36f55d70c57dac
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 the VideoLAN team
6 * $Id$
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>
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 *****************************************************************************/
28 #if !defined( __LIBVLC__ )
29 #error You are not libvlc or one of its plugins. You cannot include this file
30 #endif
32 #ifndef _VLC_THREADS_H_
33 #define _VLC_THREADS_H_
35 #include <stdio.h>
37 #if defined( UNDER_CE )
38 /* WinCE API */
39 #elif defined( WIN32 )
40 # include <process.h> /* Win32 API */
42 #elif defined( HAVE_KERNEL_SCHEDULER_H ) /* BeOS */
43 # include <kernel/OS.h>
44 # include <kernel/scheduler.h>
45 # include <byteorder.h>
47 #else /* pthreads (like Linux & BSD) */
48 # define LIBVLC_USE_PTHREAD 1
49 # define _APPLE_C_SOURCE 1 /* Proper pthread semantics on OSX */
51 # include <unistd.h> /* _POSIX_SPIN_LOCKS */
52 # include <pthread.h>
53 /* Needed for pthread_cond_timedwait */
54 # include <errno.h>
55 # ifdef DEBUG
56 # include <time.h>
57 # endif
59 #endif
61 /*****************************************************************************
62 * Constants
63 *****************************************************************************/
65 /* Thread priorities */
66 #ifdef __APPLE__
67 # define VLC_THREAD_PRIORITY_LOW (-47)
68 # define VLC_THREAD_PRIORITY_INPUT 37
69 # define VLC_THREAD_PRIORITY_AUDIO 37
70 # define VLC_THREAD_PRIORITY_VIDEO (-47)
71 # define VLC_THREAD_PRIORITY_OUTPUT 37
72 # define VLC_THREAD_PRIORITY_HIGHEST 37
74 #elif defined(SYS_BEOS)
75 # define VLC_THREAD_PRIORITY_LOW 5
76 # define VLC_THREAD_PRIORITY_INPUT 10
77 # define VLC_THREAD_PRIORITY_AUDIO 10
78 # define VLC_THREAD_PRIORITY_VIDEO 5
79 # define VLC_THREAD_PRIORITY_OUTPUT 15
80 # define VLC_THREAD_PRIORITY_HIGHEST 15
82 #elif defined(LIBVLC_USE_PTHREAD)
83 # define VLC_THREAD_PRIORITY_LOW 0
84 # define VLC_THREAD_PRIORITY_INPUT 20
85 # define VLC_THREAD_PRIORITY_AUDIO 10
86 # define VLC_THREAD_PRIORITY_VIDEO 0
87 # define VLC_THREAD_PRIORITY_OUTPUT 30
88 # define VLC_THREAD_PRIORITY_HIGHEST 40
90 #elif defined(WIN32) || defined(UNDER_CE)
91 /* Define different priorities for WinNT/2K/XP and Win9x/Me */
92 # define VLC_THREAD_PRIORITY_LOW 0
93 # define VLC_THREAD_PRIORITY_INPUT \
94 (IS_WINNT ? THREAD_PRIORITY_ABOVE_NORMAL : 0)
95 # define VLC_THREAD_PRIORITY_AUDIO \
96 (IS_WINNT ? THREAD_PRIORITY_HIGHEST : 0)
97 # define VLC_THREAD_PRIORITY_VIDEO \
98 (IS_WINNT ? 0 : THREAD_PRIORITY_BELOW_NORMAL )
99 # define VLC_THREAD_PRIORITY_OUTPUT \
100 (IS_WINNT ? THREAD_PRIORITY_ABOVE_NORMAL : 0)
101 # define VLC_THREAD_PRIORITY_HIGHEST \
102 (IS_WINNT ? THREAD_PRIORITY_TIME_CRITICAL : 0)
104 #else
105 # define VLC_THREAD_PRIORITY_LOW 0
106 # define VLC_THREAD_PRIORITY_INPUT 0
107 # define VLC_THREAD_PRIORITY_AUDIO 0
108 # define VLC_THREAD_PRIORITY_VIDEO 0
109 # define VLC_THREAD_PRIORITY_OUTPUT 0
110 # define VLC_THREAD_PRIORITY_HIGHEST 0
112 #endif
114 /*****************************************************************************
115 * Type definitions
116 *****************************************************************************/
118 #if defined( WIN32 ) || defined( UNDER_CE )
119 typedef struct
121 /* thread id */
122 DWORD id;
124 ** handle to created thread, needs be closed to dispose of it
125 ** even after thread has exited
127 HANDLE hThread;
128 } vlc_thread_t;
130 typedef BOOL (WINAPI *SIGNALOBJECTANDWAIT) ( HANDLE, HANDLE, DWORD, BOOL );
132 typedef struct
134 /* WinNT/2K/XP implementation */
135 HANDLE mutex;
136 /* Win95/98/ME implementation */
137 CRITICAL_SECTION csection;
139 vlc_object_t * p_this;
140 } vlc_mutex_t;
142 typedef struct
144 volatile int i_waiting_threads;
145 /* WinNT/2K/XP implementation */
146 HANDLE event;
147 SIGNALOBJECTANDWAIT SignalObjectAndWait;
148 /* Win95/98/ME implementation */
149 HANDLE semaphore;
150 CRITICAL_SECTION csection;
151 int i_win9x_cv;
153 vlc_object_t * p_this;
154 } vlc_cond_t;
156 typedef struct
158 DWORD handle;
159 } vlc_threadvar_t;
161 #elif defined( HAVE_KERNEL_SCHEDULER_H )
162 /* This is the BeOS implementation of the vlc threads, note that the mutex is
163 * not a real mutex and the cond_var is not like a pthread cond_var but it is
164 * enough for what we need */
166 typedef thread_id vlc_thread_t;
168 typedef struct
170 int32_t init;
171 sem_id lock;
173 vlc_object_t * p_this;
174 } vlc_mutex_t;
176 typedef struct
178 int32_t init;
179 thread_id thread;
181 vlc_object_t * p_this;
182 } vlc_cond_t;
184 typedef struct
186 } vlc_threadvar_t;
189 #else
190 typedef pthread_t vlc_thread_t;
191 typedef struct
193 pthread_mutex_t mutex;
194 vlc_object_t * p_this;
195 } vlc_mutex_t;
196 typedef struct
198 pthread_cond_t cond;
199 vlc_object_t * p_this;
200 } vlc_cond_t;
202 typedef struct
204 pthread_key_t handle;
205 } vlc_threadvar_t;
207 #endif
209 #endif /* !_VLC_THREADS_H */