1 /*****************************************************************************
2 * threads.h : threads implementation for the VideoLAN client
3 * This header provides a portable threads implementation.
4 *****************************************************************************
5 * Copyright (C) 1999, 2000 VideoLAN
6 * $Id: vlc_threads.h,v 1.1 2002/06/01 12:31:58 sam Exp $
8 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
9 * Samuel Hocevar <sam@via.ecp.fr>
10 * Gildas Bazin <gbazin@netcourrier.com>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
25 *****************************************************************************/
29 #if defined(GPROF) || defined(DEBUG)
30 # include <sys/time.h>
33 #if defined( PTH_INIT_IN_PTH_H ) /* GNU Pth */
36 #elif defined( ST_INIT_IN_ST_H ) /* State threads */
39 #elif defined( WIN32 ) /* Win32 API */
42 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) /* pthreads (like Linux & BSD) */
45 /* Needed for pthread_cond_timedwait */
48 /* This is not prototyped under Linux, though it exists. */
49 int pthread_mutexattr_setkind_np( pthread_mutexattr_t *attr, int kind );
51 #elif defined( HAVE_CTHREADS_H ) /* GNUMach */
52 # include <cthreads.h>
54 #elif defined( HAVE_KERNEL_SCHEDULER_H ) /* BeOS */
55 # include <kernel/OS.h>
56 # include <kernel/scheduler.h>
57 # include <byteorder.h>
60 # error no threads available on your system !
64 /*****************************************************************************
66 *****************************************************************************
67 * These constants are used by all threads in *_CreateThread() and
68 * *_DestroyThreads() functions. Since those calls are non-blocking, an integer
69 * value is used as a shared flag to represent the status of the thread.
70 *****************************************************************************/
72 /* Void status - this value can be used to make sure no operation is currently
73 * in progress on the concerned thread in an array of recorded threads */
74 #define THREAD_NOP 0 /* nothing happened */
77 #define THREAD_CREATE 10 /* thread is initializing */
78 #define THREAD_START 11 /* thread has forked */
79 #define THREAD_READY 19 /* thread is ready */
81 /* Destructions status */
82 #define THREAD_DESTROY 20 /* destruction order has been sent */
83 #define THREAD_END 21 /* destruction order has been received */
84 #define THREAD_OVER 29 /* thread does not exist any more */
87 #define THREAD_ERROR 30 /* an error occured */
88 #define THREAD_FATAL 31 /* an fatal error occured - program must end */
90 /*****************************************************************************
92 *****************************************************************************/
94 #if defined( PTH_INIT_IN_PTH_H )
95 typedef pth_t vlc_thread_t;
96 typedef pth_mutex_t vlc_mutex_t;
97 typedef pth_cond_t vlc_cond_t;
99 #elif defined( ST_INIT_IN_ST_H )
100 typedef st_thread_t * vlc_thread_t;
101 typedef st_mutex_t * vlc_mutex_t;
102 typedef st_cond_t * vlc_cond_t;
104 #elif defined( WIN32 )
105 typedef HANDLE vlc_thread_t;
109 CRITICAL_SECTION csection;
111 SIGNALOBJECTANDWAIT SignalObjectAndWait;
116 int i_waiting_threads;
120 typedef unsigned (__stdcall *PTHREAD_START) (void *);
122 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
123 typedef pthread_t vlc_thread_t;
124 typedef pthread_mutex_t vlc_mutex_t;
125 typedef pthread_cond_t vlc_cond_t;
127 #elif defined( HAVE_CTHREADS_H )
128 typedef cthread_t vlc_thread_t;
130 /* Those structs are the ones defined in /include/cthreads.h but we need
131 * to handle (&foo) where foo is a (mutex_t) while they handle (foo) where
132 * foo is a (mutex_t*) */
138 struct cthread_queue queue;
144 struct cthread_queue queue;
146 struct cond_imp *implications;
149 #elif defined( HAVE_KERNEL_SCHEDULER_H )
150 /* This is the BeOS implementation of the vlc threads, note that the mutex is
151 * not a real mutex and the cond_var is not like a pthread cond_var but it is
152 * enough for what wee need */
154 typedef thread_id vlc_thread_t;