* GNU/Hurd configuration and compilation fixes.
[vlc.git] / include / threads.h
blob4b400fc0ded114d14af305c5c99ae7e03805c800
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: threads.h,v 1.23 2001/08/14 04:52:39 sam Exp $
8 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
9 * Samuel Hocevar <sam@via.ecp.fr>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 #include <stdio.h>
28 #ifdef PROFILING
29 # include <sys/time.h>
30 #endif
32 #if defined( PTH_INIT_IN_PTH_H ) /* GNU Pth */
33 # include <pth.h>
35 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) /* pthreads (like Linux & BSD) */
36 # include <pthread.h>
38 #elif defined( HAVE_CTHREADS_H ) /* GNUMach */
39 # include <cthreads.h>
41 #elif defined( HAVE_KERNEL_SCHEDULER_H ) /* BeOS */
42 # undef MAX
43 # undef MIN
44 # include <kernel/OS.h>
45 # include <kernel/scheduler.h>
46 # include <byteorder.h>
48 #elif defined( WIN32 )
49 # include <windows.h>
50 # include <process.h>
52 #else
53 # error no threads available on your system !
55 #endif
57 /*****************************************************************************
58 * Constants
59 *****************************************************************************
60 * These constants are used by all threads in *_CreateThread() and
61 * *_DestroyThreads() functions. Since those calls are non-blocking, an integer
62 * value is used as a shared flag to represent the status of the thread.
63 *****************************************************************************/
65 /* Void status - this value can be used to make sure no operation is currently
66 * in progress on the concerned thread in an array of recorded threads */
67 #define THREAD_NOP 0 /* nothing happened */
69 /* Creation status */
70 #define THREAD_CREATE 10 /* thread is initializing */
71 #define THREAD_START 11 /* thread has forked */
72 #define THREAD_READY 19 /* thread is ready */
74 /* Destructions status */
75 #define THREAD_DESTROY 20 /* destruction order has been sent */
76 #define THREAD_END 21 /* destruction order has been received */
77 #define THREAD_OVER 29 /* thread does not exist any more */
79 /* Error status */
80 #define THREAD_ERROR 30 /* an error occured */
81 #define THREAD_FATAL 31 /* an fatal error occured - program must end */
83 /*****************************************************************************
84 * Types definition
85 *****************************************************************************/
87 #if defined( PTH_INIT_IN_PTH_H )
88 typedef pth_t vlc_thread_t;
89 typedef pth_mutex_t vlc_mutex_t;
90 typedef pth_cond_t vlc_cond_t;
92 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
93 typedef pthread_t vlc_thread_t;
94 typedef pthread_mutex_t vlc_mutex_t;
95 typedef pthread_cond_t vlc_cond_t;
97 #elif defined( HAVE_CTHREADS_H )
98 typedef cthread_t vlc_thread_t;
100 /* Those structs are the ones defined in /include/cthreads.h but we need
101 * to handle (*foo) where foo is a (mutex_t) while they handle (foo) where
102 * foo is a (mutex_t*) */
103 typedef struct s_mutex {
104 spin_lock_t held;
105 spin_lock_t lock;
106 char *name;
107 struct cthread_queue queue;
108 } vlc_mutex_t;
110 typedef struct s_condition {
111 spin_lock_t lock;
112 struct cthread_queue queue;
113 char *name;
114 struct cond_imp *implications;
115 } vlc_cond_t;
117 #elif defined( HAVE_KERNEL_SCHEDULER_H )
118 /* This is the BeOS implementation of the vlc threads, note that the mutex is
119 * not a real mutex and the cond_var is not like a pthread cond_var but it is
120 * enough for what wee need */
122 typedef thread_id vlc_thread_t;
124 typedef struct
126 int32 init;
127 sem_id lock;
128 } vlc_mutex_t;
130 typedef struct
132 int32 init;
133 thread_id thread;
134 } vlc_cond_t;
136 #elif defined( WIN32 )
137 typedef HANDLE vlc_thread_t;
138 typedef CRITICAL_SECTION vlc_mutex_t;
140 typedef struct
142 int i_waiting_threads;
143 HANDLE signal;
144 } vlc_cond_t;
146 typedef unsigned (__stdcall *PTHREAD_START) (void *);
148 #endif
150 typedef void *(*vlc_thread_func_t)(void *p_data);
152 /*****************************************************************************
153 * Prototypes
154 *****************************************************************************/
156 static __inline__ int vlc_threads_init ( void );
157 static __inline__ int vlc_threads_end ( void );
159 static __inline__ int vlc_mutex_init ( vlc_mutex_t * );
160 static __inline__ int vlc_mutex_lock ( vlc_mutex_t * );
161 static __inline__ int vlc_mutex_unlock ( vlc_mutex_t * );
162 static __inline__ int vlc_mutex_destroy ( vlc_mutex_t * );
164 static __inline__ int vlc_cond_init ( vlc_cond_t * );
165 static __inline__ int vlc_cond_signal ( vlc_cond_t * );
166 static __inline__ int vlc_cond_wait ( vlc_cond_t *, vlc_mutex_t * );
167 static __inline__ int vlc_cond_destroy ( vlc_cond_t * );
169 static __inline__ int vlc_thread_create ( vlc_thread_t *, char *,
170 vlc_thread_func_t, void * );
171 static __inline__ void vlc_thread_exit ( void );
172 static __inline__ void vlc_thread_join ( vlc_thread_t );
174 #if 0
175 static __inline__ int vlc_cond_timedwait( vlc_cond_t *, vlc_mutex_t *,
176 mtime_t );
177 #endif
179 #ifdef PROFILING
180 /* Wrapper function for profiling */
181 static void * vlc_thread_wrapper ( void *p_wrapper );
183 typedef struct wrapper_s
185 /* Data lock access */
186 vlc_mutex_t lock;
187 vlc_cond_t wait;
189 /* Data used to spawn the real thread */
190 vlc_thread_func_t func;
191 void *p_data;
193 /* Profiling timer passed to the thread */
194 struct itimerval itimer;
196 } wrapper_t;
198 #ifdef WIN32
199 struct itimerval
201 struct timeval it_value;
202 struct timeval it_interval;
205 int setitimer(int kind, const struct itimerval* itnew,
206 struct itimerval* itold);
208 #define ITIMER_REAL 1
209 #define ITIMER_PROF 2
211 #endif /* WIN32 */
213 #endif /* PROFILING */
215 /*****************************************************************************
216 * vlc_threads_init: initialize threads system
217 *****************************************************************************/
218 static __inline__ int vlc_threads_init( void )
220 #if defined( PTH_INIT_IN_PTH_H )
221 return pth_init();
223 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
224 return 0;
226 #elif defined( HAVE_CTHREADS_H )
227 return 0;
229 #elif defined( HAVE_KERNEL_SCHEDULER_H )
230 return 0;
232 #elif defined( WIN32 )
233 return 0;
235 #endif
238 /*****************************************************************************
239 * vlc_threads_end: stop threads system
240 *****************************************************************************/
241 static __inline__ int vlc_threads_end( void )
243 #if defined( PTH_INIT_IN_PTH_H )
244 return pth_kill();
246 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
247 return 0;
249 #elif defined( HAVE_CTHREADS_H )
250 return 0;
252 #elif defined( HAVE_KERNEL_SCHEDULER_H )
253 return 0;
255 #elif defined( WIN32 )
256 return 0;
258 #endif
261 /*****************************************************************************
262 * vlc_mutex_init: initialize a mutex
263 *****************************************************************************/
264 static __inline__ int vlc_mutex_init( vlc_mutex_t *p_mutex )
266 #if defined( PTH_INIT_IN_PTH_H )
267 return pth_mutex_init( p_mutex );
269 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
270 return pthread_mutex_init( p_mutex, NULL );
272 #elif defined( HAVE_CTHREADS_H )
273 mutex_init( p_mutex );
274 return 0;
276 #elif defined( HAVE_KERNEL_SCHEDULER_H )
278 /* check the arguments and whether it's already been initialized */
279 if( p_mutex == NULL )
281 return B_BAD_VALUE;
284 if( p_mutex->init == 9999 )
286 return EALREADY;
289 p_mutex->lock = create_sem( 1, "BeMutex" );
290 if( p_mutex->lock < B_NO_ERROR )
292 return( -1 );
295 p_mutex->init = 9999;
296 return B_OK;
298 #elif defined( WIN32 )
299 InitializeCriticalSection( p_mutex );
300 return 0;
302 #endif
305 /*****************************************************************************
306 * vlc_mutex_lock: lock a mutex
307 *****************************************************************************/
308 static __inline__ int vlc_mutex_lock( vlc_mutex_t *p_mutex )
310 #if defined( PTH_INIT_IN_PTH_H )
311 return pth_mutex_acquire( p_mutex, TRUE, NULL );
313 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
314 return pthread_mutex_lock( p_mutex );
316 #elif defined( HAVE_CTHREADS_H )
317 mutex_lock( p_mutex );
318 return 0;
320 #elif defined( HAVE_KERNEL_SCHEDULER_H )
321 status_t err;
323 if( !p_mutex )
325 return B_BAD_VALUE;
328 if( p_mutex->init < 2000 )
330 return B_NO_INIT;
333 err = acquire_sem( p_mutex->lock );
334 return err;
336 #elif defined( WIN32 )
337 EnterCriticalSection( p_mutex );
338 return 0;
340 #endif
343 /*****************************************************************************
344 * vlc_mutex_unlock: unlock a mutex
345 *****************************************************************************/
346 static __inline__ int vlc_mutex_unlock( vlc_mutex_t *p_mutex )
348 #if defined( PTH_INIT_IN_PTH_H )
349 return pth_mutex_release( p_mutex );
351 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
352 return pthread_mutex_unlock( p_mutex );
354 #elif defined( HAVE_CTHREADS_H )
355 mutex_unlock( p_mutex );
356 return 0;
358 #elif defined( HAVE_KERNEL_SCHEDULER_H )
359 if( !p_mutex)
361 return B_BAD_VALUE;
364 if( p_mutex->init < 2000 )
366 return B_NO_INIT;
369 release_sem( p_mutex->lock );
370 return B_OK;
372 #elif defined( WIN32 )
373 LeaveCriticalSection( p_mutex );
374 return 0;
376 #endif
379 /*****************************************************************************
380 * vlc_mutex_destroy: destroy a mutex
381 *****************************************************************************/
382 static __inline__ int vlc_mutex_destroy( vlc_mutex_t *p_mutex )
384 #if defined( PTH_INIT_IN_PTH_H )
385 return 0;
387 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
388 return pthread_mutex_destroy( p_mutex );
390 #elif defined( HAVE_CTHREADS_H )
391 return 0;
393 #elif defined( HAVE_KERNEL_SCHEDULER_H )
394 if( p_mutex->init == 9999 )
396 delete_sem( p_mutex->lock );
399 p_mutex->init = 0;
400 return B_OK;
402 #elif defined( WIN32 )
403 DeleteCriticalSection( p_mutex );
404 return 0;
406 #endif
409 /*****************************************************************************
410 * vlc_cond_init: initialize a condition
411 *****************************************************************************/
412 static __inline__ int vlc_cond_init( vlc_cond_t *p_condvar )
414 #if defined( PTH_INIT_IN_PTH_H )
415 return pth_cond_init( p_condvar );
417 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
418 return pthread_cond_init( p_condvar, NULL );
420 #elif defined( HAVE_CTHREADS_H )
421 /* condition_init() */
422 spin_lock_init( &p_condvar->lock );
423 cthread_queue_init( &p_condvar->queue );
424 p_condvar->name = 0;
425 p_condvar->implications = 0;
427 return 0;
429 #elif defined( HAVE_KERNEL_SCHEDULER_H )
430 if( !p_condvar )
432 return B_BAD_VALUE;
435 if( p_condvar->init == 9999 )
437 return EALREADY;
440 p_condvar->thread = -1;
441 p_condvar->init = 9999;
442 return 0;
444 #elif defined( WIN32 )
445 /* initialise counter */
446 p_condvar->i_waiting_threads = 0;
448 /* Create an auto-reset event. */
449 p_condvar->signal = CreateEvent( NULL, /* no security */
450 FALSE, /* auto-reset event */
451 FALSE, /* non-signaled initially */
452 NULL ); /* unnamed */
454 return( !p_condvar->signal );
456 #endif
459 /*****************************************************************************
460 * vlc_cond_signal: start a thread on condition completion
461 *****************************************************************************/
462 static __inline__ int vlc_cond_signal( vlc_cond_t *p_condvar )
464 #if defined( PTH_INIT_IN_PTH_H )
465 return pth_cond_notify( p_condvar, FALSE );
467 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
468 return pthread_cond_signal( p_condvar );
470 #elif defined( HAVE_CTHREADS_H )
471 /* condition_signal() */
472 if ( p_condvar->queue.head || p_condvar->implications )
474 cond_signal( (condition_t)p_condvar );
476 return 0;
478 #elif defined( HAVE_KERNEL_SCHEDULER_H )
479 if( !p_condvar )
481 return B_BAD_VALUE;
484 if( p_condvar->init < 2000 )
486 return B_NO_INIT;
489 while( p_condvar->thread != -1 )
491 thread_info info;
492 if( get_thread_info(p_condvar->thread, &info) == B_BAD_VALUE )
494 return 0;
497 if( info.state != B_THREAD_SUSPENDED )
499 /* The waiting thread is not suspended so it could
500 * have been interrupted beetwen the unlock and the
501 * suspend_thread line. That is why we sleep a little
502 * before retesting p_condver->thread. */
503 snooze( 10000 );
505 else
507 /* Ok, we have to wake up that thread */
508 resume_thread( p_condvar->thread );
509 return 0;
512 return 0;
514 #elif defined( WIN32 )
515 /* Release one waiting thread if one is available. */
516 /* For this trick to work properly, the vlc_cond_signal must be surrounded
517 * by a mutex. This will prevent another thread from stealing the signal */
518 int i_waiting_threads = p_condvar->i_waiting_threads;
519 while( p_condvar->i_waiting_threads
520 && p_condvar->i_waiting_threads == i_waiting_threads )
522 PulseEvent( p_condvar->signal );
523 Sleep( 1 ); /* deschedule the current thread */
525 return 0;
527 #endif
530 /*****************************************************************************
531 * vlc_cond_broadcast: start all threads waiting on condition completion
532 *****************************************************************************/
534 * FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME
535 * Only works with pthreads, you need to adapt it for others
536 * FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME
538 static __inline__ int vlc_cond_broadcast( vlc_cond_t *p_condvar )
540 #if defined( PTH_INIT_IN_PTH_H )
541 return pth_cond_notify( p_condvar, FALSE );
543 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
544 return pthread_cond_broadcast( p_condvar );
546 #elif defined( HAVE_CTHREADS_H )
547 /* condition_signal() */
548 if ( p_condvar->queue.head || p_condvar->implications )
550 cond_signal( (condition_t)p_condvar );
552 return 0;
554 #elif defined( HAVE_KERNEL_SCHEDULER_H )
555 if( !p_condvar )
557 return B_BAD_VALUE;
560 if( p_condvar->init < 2000 )
562 return B_NO_INIT;
565 while( p_condvar->thread != -1 )
567 thread_info info;
568 if( get_thread_info(p_condvar->thread, &info) == B_BAD_VALUE )
570 return 0;
573 if( info.state != B_THREAD_SUSPENDED )
575 /* The waiting thread is not suspended so it could
576 * have been interrupted beetwen the unlock and the
577 * suspend_thread line. That is why we sleep a little
578 * before retesting p_condver->thread. */
579 snooze( 10000 );
581 else
583 /* Ok, we have to wake up that thread */
584 resume_thread( p_condvar->thread );
585 return 0;
588 return 0;
590 #elif defined( WIN32 )
591 /* Release all waiting threads. */
592 /* For this trick to work properly, the vlc_cond_signal must be surrounded
593 * by a mutex. This will prevent another thread from stealing the signal */
594 while( p_condvar->i_waiting_threads )
596 PulseEvent( p_condvar->signal );
597 Sleep( 1 ); /* deschedule the current thread */
599 return 0;
601 #endif
604 /*****************************************************************************
605 * vlc_cond_wait: wait until condition completion
606 *****************************************************************************/
607 static __inline__ int vlc_cond_wait( vlc_cond_t *p_condvar, vlc_mutex_t *p_mutex )
609 #if defined( PTH_INIT_IN_PTH_H )
610 return pth_cond_await( p_condvar, p_mutex, NULL );
612 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
613 return pthread_cond_wait( p_condvar, p_mutex );
615 #elif defined( HAVE_CTHREADS_H )
616 condition_wait( (condition_t)p_condvar, (mutex_t)p_mutex );
617 return 0;
619 #elif defined( HAVE_KERNEL_SCHEDULER_H )
620 if( !p_condvar )
622 return B_BAD_VALUE;
625 if( !p_mutex )
627 return B_BAD_VALUE;
630 if( p_condvar->init < 2000 )
632 return B_NO_INIT;
635 /* The p_condvar->thread var is initialized before the unlock because
636 * it enables to identify when the thread is interrupted beetwen the
637 * unlock line and the suspend_thread line */
638 p_condvar->thread = find_thread( NULL );
639 vlc_mutex_unlock( p_mutex );
640 suspend_thread( p_condvar->thread );
641 p_condvar->thread = -1;
643 vlc_mutex_lock( p_mutex );
644 return 0;
646 #elif defined( WIN32 )
647 /* The ideal would be to use a function which atomically releases the
648 * mutex and initiate the waiting.
649 * Unfortunately only the SignalObjectAndWait function does this and it's
650 * only supported on WinNT/2K, furthermore it cannot take multiple
651 * events as parameters.
653 * The solution we use should however fulfill all our needs (even though
654 * it is not a correct pthreads implementation)
656 int i_result;
658 p_condvar->i_waiting_threads ++;
660 /* Release the mutex */
661 vlc_mutex_unlock( p_mutex );
663 i_result = WaitForSingleObject( p_condvar->signal, INFINITE);
665 /* maybe we should protect this with a mutex ? */
666 p_condvar->i_waiting_threads --;
668 /* Reacquire the mutex before returning. */
669 vlc_mutex_lock( p_mutex );
671 return( i_result == WAIT_FAILED );
673 #endif
676 /*****************************************************************************
677 * vlc_cond_destroy: destroy a condition
678 *****************************************************************************/
679 static __inline__ int vlc_cond_destroy( vlc_cond_t *p_condvar )
681 #if defined( PTH_INIT_IN_PTH_H )
682 return 0;
684 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
685 return pthread_cond_destroy( p_condvar );
687 #elif defined( HAVE_CTHREADS_H )
688 return 0;
690 #elif defined( HAVE_KERNEL_SCHEDULER_H )
691 p_condvar->init = 0;
692 return 0;
694 #elif defined( WIN32 )
695 return( !CloseHandle( p_condvar->signal ) );
697 #endif
700 /*****************************************************************************
701 * vlc_thread_create: create a thread
702 *****************************************************************************/
703 static __inline__ int vlc_thread_create( vlc_thread_t *p_thread,
704 char *psz_name,
705 vlc_thread_func_t func,
706 void *p_data )
708 int i_ret;
710 #ifdef PROFILING
711 wrapper_t wrapper;
713 /* Initialize the wrapper structure */
714 wrapper.func = func;
715 wrapper.p_data = p_data;
716 getitimer( ITIMER_PROF, &wrapper.itimer );
717 vlc_mutex_init( &wrapper.lock );
718 vlc_cond_init( &wrapper.wait );
719 vlc_mutex_lock( &wrapper.lock );
721 /* Alter user-passed data so that we call the wrapper instead
722 * of the real function */
723 p_data = &wrapper;
724 func = vlc_thread_wrapper;
725 #endif
727 #if defined( PTH_INIT_IN_PTH_H )
728 *p_thread = pth_spawn( PTH_ATTR_DEFAULT, func, p_data );
729 i_ret = ( p_thread == NULL );
731 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
732 i_ret = pthread_create( p_thread, NULL, func, p_data );
734 #elif defined( HAVE_CTHREADS_H )
735 *p_thread = cthread_fork( (cthread_fn_t)func, (any_t)p_data );
736 i_ret = 0;
738 #elif defined( HAVE_KERNEL_SCHEDULER_H )
739 *p_thread = spawn_thread( (thread_func)func, psz_name,
740 B_NORMAL_PRIORITY, p_data );
741 i_ret = resume_thread( *p_thread );
743 #elif defined( WIN32 )
744 #if 0
745 DWORD threadID;
746 /* This method is not recommended when using the MSVCRT C library,
747 * so we'll have to use _beginthreadex instead */
748 *p_thread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE) func,
749 p_data, 0, &threadID);
750 #endif
751 unsigned threadID;
752 /* When using the MSVCRT C library you have to use the _beginthreadex
753 * function instead of CreateThread, otherwise you'll end up with memory
754 * leaks and the signal function not working */
755 *p_thread = (HANDLE)_beginthreadex(NULL, 0, (PTHREAD_START) func,
756 p_data, 0, &threadID);
758 i_ret = ( *p_thread ? 0 : 1 );
760 #endif
762 #ifdef PROFILING
763 if( i_ret == 0 )
765 vlc_cond_wait( &wrapper.wait, &wrapper.lock );
768 vlc_mutex_unlock( &wrapper.lock );
769 vlc_mutex_destroy( &wrapper.lock );
770 vlc_cond_destroy( &wrapper.wait );
771 #endif
773 return i_ret;
776 /*****************************************************************************
777 * vlc_thread_exit: terminate a thread
778 *****************************************************************************/
779 static __inline__ void vlc_thread_exit( void )
781 #if defined( PTH_INIT_IN_PTH_H )
782 pth_exit( 0 );
784 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
785 pthread_exit( 0 );
787 #elif defined( HAVE_CTHREADS_H )
788 int result;
789 cthread_exit( &result );
791 #elif defined( HAVE_KERNEL_SCHEDULER_H )
792 exit_thread( 0 );
794 #elif defined( WIN32 )
795 #if 0
796 ExitThread( 0 );
797 #endif
798 /* For now we don't close the thread handles (because of race conditions).
799 * Need to be looked at. */
800 _endthreadex(0);
802 #endif
805 /*****************************************************************************
806 * vlc_thread_join: wait until a thread exits
807 *****************************************************************************/
808 static __inline__ void vlc_thread_join( vlc_thread_t thread )
810 #if defined( PTH_INIT_IN_PTH_H )
811 pth_join( thread, NULL );
813 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
814 pthread_join( thread, NULL );
816 #elif defined( HAVE_CTHREADS_H )
817 cthread_join( thread );
819 #elif defined( HAVE_KERNEL_SCHEDULER_H )
820 int32 exit_value;
821 wait_for_thread( thread, &exit_value );
823 #elif defined( WIN32 )
824 WaitForSingleObject( thread, INFINITE);
826 #endif
829 #ifdef PROFILING
830 static void *vlc_thread_wrapper( void *p_wrapper )
832 /* Put user data in thread-local variables */
833 void * p_data = ((wrapper_t*)p_wrapper)->p_data;
834 vlc_thread_func_t func = ((wrapper_t*)p_wrapper)->func;
836 /* Set the profile timer value */
837 setitimer( ITIMER_PROF, &((wrapper_t*)p_wrapper)->itimer, NULL );
839 /* Tell the calling thread that we don't need its data anymore */
840 vlc_mutex_lock( &((wrapper_t*)p_wrapper)->lock );
841 vlc_cond_signal( &((wrapper_t*)p_wrapper)->wait );
842 vlc_mutex_unlock( &((wrapper_t*)p_wrapper)->lock );
844 /* Call the real function */
845 return func( p_data );
847 #endif