]> git.sesse.net Git - vlc/blob - include/vlc_threads.h
Remove useless include
[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 the VideoLAN team
6  * $Id$
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26  *****************************************************************************/
27
28 #if !defined( __LIBVLC__ )
29   #error You are not libvlc or one of its plugins. You cannot include this file
30 #endif
31
32 #ifndef _VLC_THREADS_H_
33 #define _VLC_THREADS_H_
34
35 #if defined( UNDER_CE )
36                                                                 /* WinCE API */
37 #elif defined( WIN32 )
38 #   include <process.h>                                         /* Win32 API */
39 #   include <errno.h>
40
41 #elif defined( HAVE_KERNEL_SCHEDULER_H )                             /* BeOS */
42 #   include <kernel/OS.h>
43 #   include <kernel/scheduler.h>
44 #   include <byteorder.h>
45
46 #else                                         /* pthreads (like Linux & BSD) */
47 #   define LIBVLC_USE_PTHREAD 1
48 #   define _APPLE_C_SOURCE    1 /* Proper pthread semantics on OSX */
49
50 #   include <unistd.h> /* _POSIX_SPIN_LOCKS */
51 #   include <pthread.h>
52     /* Needed for pthread_cond_timedwait */
53 #   include <errno.h>
54 #   include <time.h>
55
56 #endif
57
58 /*****************************************************************************
59  * Constants
60  *****************************************************************************/
61
62 /* Thread priorities */
63 #ifdef __APPLE__
64 #   define VLC_THREAD_PRIORITY_LOW (-47)
65 #   define VLC_THREAD_PRIORITY_INPUT 37
66 #   define VLC_THREAD_PRIORITY_AUDIO 37
67 #   define VLC_THREAD_PRIORITY_VIDEO (-47)
68 #   define VLC_THREAD_PRIORITY_OUTPUT 37
69 #   define VLC_THREAD_PRIORITY_HIGHEST 37
70
71 #elif defined(SYS_BEOS)
72 #   define VLC_THREAD_PRIORITY_LOW 5
73 #   define VLC_THREAD_PRIORITY_INPUT 10
74 #   define VLC_THREAD_PRIORITY_AUDIO 10
75 #   define VLC_THREAD_PRIORITY_VIDEO 5
76 #   define VLC_THREAD_PRIORITY_OUTPUT 15
77 #   define VLC_THREAD_PRIORITY_HIGHEST 15
78
79 #elif defined(LIBVLC_USE_PTHREAD)
80 #   define VLC_THREAD_PRIORITY_LOW 0
81 #   define VLC_THREAD_PRIORITY_INPUT 20
82 #   define VLC_THREAD_PRIORITY_AUDIO 10
83 #   define VLC_THREAD_PRIORITY_VIDEO 0
84 #   define VLC_THREAD_PRIORITY_OUTPUT 30
85 #   define VLC_THREAD_PRIORITY_HIGHEST 40
86
87 #elif defined(WIN32) || defined(UNDER_CE)
88 /* Define different priorities for WinNT/2K/XP and Win9x/Me */
89 #   define VLC_THREAD_PRIORITY_LOW 0
90 #   define VLC_THREAD_PRIORITY_INPUT \
91         (IS_WINNT ? THREAD_PRIORITY_ABOVE_NORMAL : 0)
92 #   define VLC_THREAD_PRIORITY_AUDIO \
93         (IS_WINNT ? THREAD_PRIORITY_HIGHEST : 0)
94 #   define VLC_THREAD_PRIORITY_VIDEO \
95         (IS_WINNT ? 0 : THREAD_PRIORITY_BELOW_NORMAL )
96 #   define VLC_THREAD_PRIORITY_OUTPUT \
97         (IS_WINNT ? THREAD_PRIORITY_ABOVE_NORMAL : 0)
98 #   define VLC_THREAD_PRIORITY_HIGHEST \
99         (IS_WINNT ? THREAD_PRIORITY_TIME_CRITICAL : 0)
100
101 #else
102 #   define VLC_THREAD_PRIORITY_LOW 0
103 #   define VLC_THREAD_PRIORITY_INPUT 0
104 #   define VLC_THREAD_PRIORITY_AUDIO 0
105 #   define VLC_THREAD_PRIORITY_VIDEO 0
106 #   define VLC_THREAD_PRIORITY_OUTPUT 0
107 #   define VLC_THREAD_PRIORITY_HIGHEST 0
108
109 #endif
110
111 /*****************************************************************************
112  * Type definitions
113  *****************************************************************************/
114
115 #if defined( WIN32 ) || defined( UNDER_CE )
116 typedef struct
117 {
118     /* thread id */
119     DWORD  id;
120     /*
121     ** handle to created thread, needs be closed to dispose of it
122     ** even after thread has exited
123     */
124     HANDLE hThread;
125 } vlc_thread_t;
126
127 typedef BOOL (WINAPI *SIGNALOBJECTANDWAIT) ( HANDLE, HANDLE, DWORD, BOOL );
128
129 typedef HANDLE  vlc_mutex_t;
130
131 typedef struct
132 {
133     volatile int        i_waiting_threads;
134     HANDLE              event;
135 } vlc_cond_t;
136
137 typedef DWORD   vlc_threadvar_t;
138
139 #elif defined( HAVE_KERNEL_SCHEDULER_H )
140 /* This is the BeOS implementation of the vlc threads, note that the mutex is
141  * not a real mutex and the cond_var is not like a pthread cond_var but it is
142  * enough for what we need */
143
144 typedef thread_id vlc_thread_t;
145
146 typedef struct
147 {
148     int32_t         init;
149     sem_id          lock;
150 } vlc_mutex_t;
151
152 typedef struct
153 {
154     int32_t         init;
155     thread_id       thread;
156 } vlc_cond_t;
157
158 typedef struct
159 {
160 } vlc_threadvar_t;
161
162
163 #else
164 typedef pthread_t       vlc_thread_t;
165 typedef pthread_mutex_t vlc_mutex_t;
166 typedef pthread_cond_t  vlc_cond_t;
167 typedef pthread_key_t   vlc_threadvar_t;
168
169 #endif
170
171 #endif /* !_VLC_THREADS_H */