vlc_threads.h 5.33 KB
Newer Older
1
/*****************************************************************************
2 3
 * vlc_threads.h : threads implementation for the VideoLAN client
 * This header provides portable declarations for mutexes & conditions
4
 *****************************************************************************
5
 * Copyright (C) 1999, 2002 the VideoLAN team
Gildas Bazin's avatar
Gildas Bazin committed
6
 * $Id$
7
 *
8 9
 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
 *          Samuel Hocevar <sam@via.ecp.fr>
Gildas Bazin's avatar
 
Gildas Bazin committed
10
 *          Gildas Bazin <gbazin@netcourrier.com>
11
 *          Christophe Massiot <massiot@via.ecp.fr>
12 13 14 15 16
 *
 * 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.
17
 *
18 19
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
22
 *
23 24
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
Antoine Cellerier's avatar
Antoine Cellerier committed
25
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26
 *****************************************************************************/
27

Clément Stenac's avatar
Clément Stenac committed
28 29 30 31
#if !defined( __LIBVLC__ )
  #error You are not libvlc or one of its plugins. You cannot include this file
#endif

32 33 34
#ifndef _VLC_THREADS_H_
#define _VLC_THREADS_H_

35
#if defined( UNDER_CE )
36
                                                                /* WinCE API */
37 38
#elif defined( WIN32 )
#   include <process.h>                                         /* Win32 API */
39
#   include <errno.h>
Sam Hocevar's avatar
 
Sam Hocevar committed
40

41 42 43 44 45
#elif defined( HAVE_KERNEL_SCHEDULER_H )                             /* BeOS */
#   include <kernel/OS.h>
#   include <kernel/scheduler.h>
#   include <byteorder.h>

46
#else                                         /* pthreads (like Linux & BSD) */
47
#   define LIBVLC_USE_PTHREAD 1
48
#   define _APPLE_C_SOURCE    1 /* Proper pthread semantics on OSX */
49

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
50
#   include <unistd.h> /* _POSIX_SPIN_LOCKS */
Sam Hocevar's avatar
 
Sam Hocevar committed
51
#   include <pthread.h>
52 53
    /* Needed for pthread_cond_timedwait */
#   include <errno.h>
54
#   include <time.h>
55

56
#endif
57

58
/*****************************************************************************
Vincent Seguin's avatar
Vincent Seguin committed
59
 * Constants
60
 *****************************************************************************/
Vincent Seguin's avatar
Vincent Seguin committed
61

62
/* Thread priorities */
63
#ifdef __APPLE__
64 65 66 67 68
#   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
69
#   define VLC_THREAD_PRIORITY_HIGHEST 37
Vincent Seguin's avatar
Vincent Seguin committed
70

71 72 73 74 75 76
#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
77
#   define VLC_THREAD_PRIORITY_HIGHEST 15
78

79
#elif defined(LIBVLC_USE_PTHREAD)
80 81 82 83 84
#   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
85
#   define VLC_THREAD_PRIORITY_HIGHEST 40
86

87
#elif defined(WIN32) || defined(UNDER_CE)
Gildas Bazin's avatar
 
Gildas Bazin committed
88
/* Define different priorities for WinNT/2K/XP and Win9x/Me */
89
#   define VLC_THREAD_PRIORITY_LOW 0
Gildas Bazin's avatar
 
Gildas Bazin committed
90
#   define VLC_THREAD_PRIORITY_INPUT \
Gildas Bazin's avatar
Gildas Bazin committed
91
        (IS_WINNT ? THREAD_PRIORITY_ABOVE_NORMAL : 0)
Gildas Bazin's avatar
 
Gildas Bazin committed
92 93
#   define VLC_THREAD_PRIORITY_AUDIO \
        (IS_WINNT ? THREAD_PRIORITY_HIGHEST : 0)
Gildas Bazin's avatar
 
Gildas Bazin committed
94 95
#   define VLC_THREAD_PRIORITY_VIDEO \
        (IS_WINNT ? 0 : THREAD_PRIORITY_BELOW_NORMAL )
Gildas Bazin's avatar
 
Gildas Bazin committed
96 97 98 99
#   define VLC_THREAD_PRIORITY_OUTPUT \
        (IS_WINNT ? THREAD_PRIORITY_ABOVE_NORMAL : 0)
#   define VLC_THREAD_PRIORITY_HIGHEST \
        (IS_WINNT ? THREAD_PRIORITY_TIME_CRITICAL : 0)
100

101 102 103 104
#else
#   define VLC_THREAD_PRIORITY_LOW 0
#   define VLC_THREAD_PRIORITY_INPUT 0
#   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
Vincent Seguin's avatar
Vincent Seguin committed
108

109
#endif
Vincent Seguin's avatar
Vincent Seguin committed
110

111
/*****************************************************************************
Gildas Bazin's avatar
 
Gildas Bazin committed
112
 * Type definitions
113
 *****************************************************************************/
114

115
#if defined( WIN32 ) || defined( UNDER_CE )
116 117 118 119 120 121 122 123 124 125 126
typedef struct
{
    /* thread id */
    DWORD  id;
    /*
    ** handle to created thread, needs be closed to dispose of it
    ** even after thread has exited
    */
    HANDLE hThread;
} vlc_thread_t;

Gildas Bazin's avatar
 
Gildas Bazin committed
127
typedef BOOL (WINAPI *SIGNALOBJECTANDWAIT) ( HANDLE, HANDLE, DWORD, BOOL );
Sam Hocevar's avatar
 
Sam Hocevar committed
128

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
129
typedef HANDLE  vlc_mutex_t;
Sam Hocevar's avatar
 
Sam Hocevar committed
130 131 132

typedef struct
{
Gildas Bazin's avatar
 
Gildas Bazin committed
133 134
    volatile int        i_waiting_threads;
    HANDLE              event;
Sam Hocevar's avatar
 
Sam Hocevar committed
135 136
} vlc_cond_t;

137
typedef DWORD   vlc_threadvar_t;
138

139 140 141
#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
Rémi Denis-Courmont's avatar
Typo  
Rémi Denis-Courmont committed
142
 * enough for what we need */
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157

typedef thread_id vlc_thread_t;

typedef struct
{
    int32_t         init;
    sem_id          lock;
} vlc_mutex_t;

typedef struct
{
    int32_t         init;
    thread_id       thread;
} vlc_cond_t;

158 159 160 161 162
typedef struct
{
} vlc_threadvar_t;


163
#else
164
typedef pthread_t       vlc_thread_t;
165 166 167
typedef pthread_mutex_t vlc_mutex_t;
typedef pthread_cond_t  vlc_cond_t;
typedef pthread_key_t   vlc_threadvar_t;
168

Gildas Bazin's avatar
 
Gildas Bazin committed
169 170
#endif

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
171
#endif /* !_VLC_THREADS_H */