]> git.sesse.net Git - vlc/blob - include/vlc_threads_funcs.h
Attempt to fix MacOS build
[vlc] / include / vlc_threads_funcs.h
1 /*****************************************************************************
2  * vlc_threads_funcs.h : threads implementation for the VideoLAN client
3  * This header provides a portable threads implementation.
4  *****************************************************************************
5  * Copyright (C) 1999-2007 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_THREADFUNCS_H_
33 #define _VLC_THREADFUNCS_H_
34
35 /*****************************************************************************
36  * Function definitions
37  *****************************************************************************/
38 VLC_EXPORT( int,  __vlc_mutex_init,    ( vlc_object_t *, vlc_mutex_t * ) );
39 VLC_EXPORT( int,  __vlc_mutex_destroy, ( const char *, int, vlc_mutex_t * ) );
40 VLC_EXPORT( int,  __vlc_cond_init,     ( vlc_object_t *, vlc_cond_t * ) );
41 VLC_EXPORT( int,  __vlc_cond_destroy,  ( const char *, int, vlc_cond_t * ) );
42 VLC_EXPORT( int, __vlc_threadvar_create, (vlc_object_t *, vlc_threadvar_t * ) );
43 VLC_EXPORT( int,  __vlc_thread_create, ( vlc_object_t *, const char *, int, const char *, void * ( * ) ( void * ), int, vlc_bool_t ) );
44 VLC_EXPORT( int,  __vlc_thread_set_priority, ( vlc_object_t *, const char *, int, int ) );
45 VLC_EXPORT( void, __vlc_thread_ready,  ( vlc_object_t * ) );
46 VLC_EXPORT( void, __vlc_thread_join,   ( vlc_object_t *, const char *, int ) );
47
48 #include <errno.h>
49
50 /*****************************************************************************
51  * vlc_threads_init: initialize threads system
52  *****************************************************************************/
53 #define vlc_threads_init( P_THIS )                                          \
54     __vlc_threads_init( VLC_OBJECT(P_THIS) )
55
56 /*****************************************************************************
57  * vlc_threads_end: deinitialize threads system
58  *****************************************************************************/
59 #define vlc_threads_end( P_THIS )                                           \
60     __vlc_threads_end( VLC_OBJECT(P_THIS) )
61
62 /*****************************************************************************
63  * vlc_mutex_init: initialize a mutex
64  *****************************************************************************/
65 #define vlc_mutex_init( P_THIS, P_MUTEX )                                   \
66     __vlc_mutex_init( VLC_OBJECT(P_THIS), P_MUTEX )
67
68 /*****************************************************************************
69  * vlc_mutex_lock: lock a mutex
70  *****************************************************************************/
71 #define vlc_mutex_lock( P_MUTEX )                                           \
72     __vlc_mutex_lock( __FILE__, __LINE__, P_MUTEX )
73
74 #ifdef __APPLE__
75 #   define CAST_PTHREAD_TO_INT(t) (unsigned long int)(uintptr_t)(void *)t
76 #else
77 #   define CAST_PTHREAD_TO_INT(t) (unsigned long int)t
78 #endif
79
80 static inline int __vlc_mutex_lock( const char * psz_file, int i_line,
81                                     vlc_mutex_t * p_mutex )
82 {
83     int i_result;
84     /* In case of error : */
85     unsigned long int i_thread = 0;
86     const char * psz_error = "";
87
88 #if defined( PTH_INIT_IN_PTH_H )
89     i_result = ( pth_mutex_acquire( &p_mutex->mutex, FALSE, NULL ) == FALSE );
90
91 #elif defined( ST_INIT_IN_ST_H )
92     i_result = st_mutex_lock( p_mutex->mutex );
93
94 #elif defined( UNDER_CE )
95     EnterCriticalSection( &p_mutex->csection );
96     i_result = 0;
97
98 #elif defined( WIN32 )
99     if( p_mutex->mutex )
100     {
101         WaitForSingleObject( p_mutex->mutex, INFINITE );
102     }
103     else
104     {
105         EnterCriticalSection( &p_mutex->csection );
106     }
107     i_result = 0;
108
109 #elif defined( HAVE_KERNEL_SCHEDULER_H )
110     if( p_mutex == NULL )
111     {
112         i_result = B_BAD_VALUE;
113     }
114     else if( p_mutex->init < 2000 )
115     {
116         i_result = B_NO_INIT;
117     }
118     else
119     {
120         i_result = acquire_sem( p_mutex->lock );
121     }
122
123 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
124 #   define vlc_assert_locked( m ) \
125            assert (pthread_mutex_lock (&((m)->mutex)) == EDEADLK)
126
127     i_result = pthread_mutex_lock( &p_mutex->mutex );
128     if ( i_result )
129     {
130         i_thread = CAST_PTHREAD_TO_INT(pthread_self());
131         psz_error = strerror(i_result);
132     }
133
134 #elif defined( HAVE_CTHREADS_H )
135     mutex_lock( p_mutex->mutex );
136     i_result = 0;
137
138 #endif
139
140     if( i_result )
141     {
142         msg_Err( p_mutex->p_this,
143                  "thread %li: mutex_lock failed at %s:%d (%d:%s)",
144                  i_thread, psz_file, i_line, i_result, psz_error );
145     }
146     return i_result;
147 }
148
149 #ifndef vlc_assert_locked
150 # define vlc_assert_locked( m ) (void)0
151 #endif
152
153 /*****************************************************************************
154  * vlc_mutex_unlock: unlock a mutex
155  *****************************************************************************/
156 #define vlc_mutex_unlock( P_MUTEX )                                         \
157     __vlc_mutex_unlock( __FILE__, __LINE__, P_MUTEX )
158
159 static inline int __vlc_mutex_unlock( const char * psz_file, int i_line,
160                                       vlc_mutex_t *p_mutex )
161 {
162     int i_result;
163     /* In case of error : */
164     unsigned long int i_thread = 0;
165     const char * psz_error = "";
166
167 #if defined( PTH_INIT_IN_PTH_H )
168     i_result = ( pth_mutex_release( &p_mutex->mutex ) == FALSE );
169
170 #elif defined( ST_INIT_IN_ST_H )
171     i_result = st_mutex_unlock( p_mutex->mutex );
172
173 #elif defined( UNDER_CE )
174     LeaveCriticalSection( &p_mutex->csection );
175     i_result = 0;
176
177 #elif defined( WIN32 )
178     if( p_mutex->mutex )
179     {
180         ReleaseMutex( p_mutex->mutex );
181     }
182     else
183     {
184         LeaveCriticalSection( &p_mutex->csection );
185     }
186     i_result = 0;
187
188 #elif defined( HAVE_KERNEL_SCHEDULER_H )
189     if( p_mutex == NULL )
190     {
191         i_result = B_BAD_VALUE;
192     }
193     else if( p_mutex->init < 2000 )
194     {
195         i_result = B_NO_INIT;
196     }
197     else
198     {
199         release_sem( p_mutex->lock );
200         return B_OK;
201     }
202
203 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
204     i_result = pthread_mutex_unlock( &p_mutex->mutex );
205     if ( i_result )
206     {
207         i_thread = CAST_PTHREAD_TO_INT(pthread_self());
208         psz_error = strerror(i_result);
209     }
210
211 #elif defined( HAVE_CTHREADS_H )
212     mutex_unlock( p_mutex );
213     i_result = 0;
214
215 #endif
216
217     if( i_result )
218     {
219         msg_Err( p_mutex->p_this,
220                  "thread %li: mutex_unlock failed at %s:%d (%d:%s)",
221                  i_thread, psz_file, i_line, i_result, psz_error );
222     }
223
224     return i_result;
225 }
226
227 /*****************************************************************************
228  * vlc_mutex_destroy: destroy a mutex
229  *****************************************************************************/
230 #define vlc_mutex_destroy( P_MUTEX )                                        \
231     __vlc_mutex_destroy( __FILE__, __LINE__, P_MUTEX )
232
233 /*****************************************************************************
234  * vlc_cond_init: initialize a condition
235  *****************************************************************************/
236 #define vlc_cond_init( P_THIS, P_COND )                                     \
237     __vlc_cond_init( VLC_OBJECT(P_THIS), P_COND )
238
239 /*****************************************************************************
240  * vlc_cond_signal: start a thread on condition completion
241  *****************************************************************************/
242 #define vlc_cond_signal( P_COND )                                           \
243     __vlc_cond_signal( __FILE__, __LINE__, P_COND )
244
245 static inline int __vlc_cond_signal( const char * psz_file, int i_line,
246                                      vlc_cond_t *p_condvar )
247 {
248     int i_result;
249     /* In case of error : */
250     unsigned long int i_thread = 0;
251     const char * psz_error = "";
252
253 #if defined( PTH_INIT_IN_PTH_H )
254     i_result = ( pth_cond_notify( &p_condvar->cond, FALSE ) == FALSE );
255
256 #elif defined( ST_INIT_IN_ST_H )
257     i_result = st_cond_signal( p_condvar->cond );
258
259 #elif defined( UNDER_CE )
260     PulseEvent( p_condvar->event );
261     i_result = 0;
262
263 #elif defined( WIN32 )
264     /* Release one waiting thread if one is available. */
265     /* For this trick to work properly, the vlc_cond_signal must be surrounded
266      * by a mutex. This will prevent another thread from stealing the signal */
267     if( !p_condvar->semaphore )
268     {
269         PulseEvent( p_condvar->event );
270     }
271     else if( p_condvar->i_win9x_cv == 1 )
272     {
273         /* Wait for the gate to be open */
274         WaitForSingleObject( p_condvar->event, INFINITE );
275
276         if( p_condvar->i_waiting_threads )
277         {
278             /* Using a semaphore exposes us to a race condition. It is
279              * possible for another thread to start waiting on the semaphore
280              * just after we signaled it and thus steal the signal.
281              * We have to prevent new threads from entering the cond_wait(). */
282             ResetEvent( p_condvar->event );
283
284             /* A semaphore is used here because Win9x doesn't have
285              * SignalObjectAndWait() and thus a race condition exists
286              * during the time we release the mutex and the time we start
287              * waiting on the event (more precisely, the signal can sometimes
288              * be missed by the waiting thread if we use PulseEvent()). */
289             ReleaseSemaphore( p_condvar->semaphore, 1, 0 );
290         }
291     }
292     else
293     {
294         if( p_condvar->i_waiting_threads )
295         {
296             ReleaseSemaphore( p_condvar->semaphore, 1, 0 );
297
298             /* Wait for the last thread to be awakened */
299             WaitForSingleObject( p_condvar->event, INFINITE );
300         }
301     }
302     i_result = 0;
303
304 #elif defined( HAVE_KERNEL_SCHEDULER_H )
305     if( p_condvar == NULL )
306     {
307         i_result = B_BAD_VALUE;
308     }
309     else if( p_condvar->init < 2000 )
310     {
311         i_result = B_NO_INIT;
312     }
313     else
314     {
315         while( p_condvar->thread != -1 )
316         {
317             thread_info info;
318             if( get_thread_info(p_condvar->thread, &info) == B_BAD_VALUE )
319             {
320                 return 0;
321             }
322
323             if( info.state != B_THREAD_SUSPENDED )
324             {
325                 /* The  waiting thread is not suspended so it could
326                  * have been interrupted beetwen the unlock and the
327                  * suspend_thread line. That is why we sleep a little
328                  * before retesting p_condver->thread. */
329                 snooze( 10000 );
330             }
331             else
332             {
333                 /* Ok, we have to wake up that thread */
334                 resume_thread( p_condvar->thread );
335                 return 0;
336             }
337         }
338         i_result = 0;
339     }
340
341 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
342     i_result = pthread_cond_signal( &p_condvar->cond );
343     if ( i_result )
344     {
345         i_thread = CAST_PTHREAD_TO_INT(pthread_self());
346         psz_error = strerror(i_result);
347     }
348
349 #elif defined( HAVE_CTHREADS_H )
350     /* condition_signal() */
351     if ( p_condvar->queue.head || p_condvar->implications )
352     {
353         cond_signal( (condition_t)p_condvar );
354     }
355     i_result = 0;
356
357 #endif
358
359     if( i_result )
360     {
361         msg_Err( p_condvar->p_this,
362                  "thread %li: cond_signal failed at %s:%d (%d:%s)",
363                  i_thread, psz_file, i_line, i_result, psz_error );
364     }
365
366     return i_result;
367 }
368
369 /*****************************************************************************
370  * vlc_cond_wait: wait until condition completion
371  *****************************************************************************/
372 #define vlc_cond_wait( P_COND, P_MUTEX )                                     \
373     __vlc_cond_wait( __FILE__, __LINE__, P_COND, P_MUTEX  )
374
375 static inline int __vlc_cond_wait( const char * psz_file, int i_line,
376                                    vlc_cond_t *p_condvar, vlc_mutex_t *p_mutex )
377 {
378     int i_result;
379     /* In case of error : */
380     unsigned long int i_thread = 0;
381     const char * psz_error = "";
382
383 #if defined( PTH_INIT_IN_PTH_H )
384     i_result = ( pth_cond_await( &p_condvar->cond, &p_mutex->mutex, NULL )
385                  == FALSE );
386
387 #elif defined( ST_INIT_IN_ST_H )
388     st_mutex_unlock( p_mutex->mutex );
389     i_result = st_cond_wait( p_condvar->cond );
390     st_mutex_lock( p_mutex->mutex );
391
392 #elif defined( UNDER_CE )
393     p_condvar->i_waiting_threads++;
394     LeaveCriticalSection( &p_mutex->csection );
395     WaitForSingleObject( p_condvar->event, INFINITE );
396     p_condvar->i_waiting_threads--;
397
398     /* Reacquire the mutex before returning. */
399     vlc_mutex_lock( p_mutex );
400
401     i_result = 0;
402
403 #elif defined( WIN32 )
404     if( !p_condvar->semaphore )
405     {
406         /* Increase our wait count */
407         p_condvar->i_waiting_threads++;
408
409         if( p_mutex->mutex )
410         {
411             /* It is only possible to atomically release the mutex and
412              * initiate the waiting on WinNT/2K/XP. Win9x doesn't have
413              * SignalObjectAndWait(). */
414             p_condvar->SignalObjectAndWait( p_mutex->mutex,
415                                             p_condvar->event,
416                                             INFINITE, FALSE );
417         }
418         else
419         {
420             LeaveCriticalSection( &p_mutex->csection );
421             WaitForSingleObject( p_condvar->event, INFINITE );
422         }
423
424         p_condvar->i_waiting_threads--;
425     }
426     else if( p_condvar->i_win9x_cv == 1 )
427     {
428         int i_waiting_threads;
429
430         /* Wait for the gate to be open */
431         WaitForSingleObject( p_condvar->event, INFINITE );
432
433         /* Increase our wait count */
434         p_condvar->i_waiting_threads++;
435
436         LeaveCriticalSection( &p_mutex->csection );
437         WaitForSingleObject( p_condvar->semaphore, INFINITE );
438
439         /* Decrement and test must be atomic */
440         EnterCriticalSection( &p_condvar->csection );
441
442         /* Decrease our wait count */
443         i_waiting_threads = --p_condvar->i_waiting_threads;
444
445         LeaveCriticalSection( &p_condvar->csection );
446
447         /* Reopen the gate if we were the last waiting thread */
448         if( !i_waiting_threads )
449             SetEvent( p_condvar->event );
450     }
451     else
452     {
453         int i_waiting_threads;
454
455         /* Increase our wait count */
456         p_condvar->i_waiting_threads++;
457
458         LeaveCriticalSection( &p_mutex->csection );
459         WaitForSingleObject( p_condvar->semaphore, INFINITE );
460
461         /* Decrement and test must be atomic */
462         EnterCriticalSection( &p_condvar->csection );
463
464         /* Decrease our wait count */
465         i_waiting_threads = --p_condvar->i_waiting_threads;
466
467         LeaveCriticalSection( &p_condvar->csection );
468
469         /* Signal that the last waiting thread just went through */
470         if( !i_waiting_threads )
471             SetEvent( p_condvar->event );
472     }
473
474     /* Reacquire the mutex before returning. */
475     vlc_mutex_lock( p_mutex );
476
477     i_result = 0;
478
479 #elif defined( HAVE_KERNEL_SCHEDULER_H )
480     if( p_condvar == NULL )
481     {
482         i_result = B_BAD_VALUE;
483     }
484     else if( p_mutex == NULL )
485     {
486         i_result = B_BAD_VALUE;
487     }
488     else if( p_condvar->init < 2000 )
489     {
490         i_result = B_NO_INIT;
491     }
492
493     /* The p_condvar->thread var is initialized before the unlock because
494      * it enables to identify when the thread is interrupted beetwen the
495      * unlock line and the suspend_thread line */
496     p_condvar->thread = find_thread( NULL );
497     vlc_mutex_unlock( p_mutex );
498     suspend_thread( p_condvar->thread );
499     p_condvar->thread = -1;
500
501     vlc_mutex_lock( p_mutex );
502     i_result = 0;
503
504 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
505
506 #   ifdef DEBUG
507     /* In debug mode, timeout */
508     struct timespec timeout;
509
510 # if defined (_POSIX_CLOCK_MONOTONIC) && (_POSIX_CLOCK_MONOTONIC >= 0)
511     if( clock_gettime( CLOCK_MONOTONIC, &timeout ) )
512 # endif
513         clock_gettime( CLOCK_REALTIME, &timeout );
514
515     timeout.tv_sec += THREAD_COND_TIMEOUT;
516
517     i_result = pthread_cond_timedwait( &p_condvar->cond, &p_mutex->mutex,
518                                        &timeout );
519
520     if( i_result == ETIMEDOUT )
521     {
522         msg_Dbg( p_condvar->p_this,
523                   "thread %li: possible condition deadlock "
524                   "at %s:%d (%s)", CAST_PTHREAD_TO_INT(pthread_self()),
525                   psz_file, i_line, strerror(i_result) );
526
527         i_result = pthread_cond_wait( &p_condvar->cond, &p_mutex->mutex );
528     }
529
530 #   else
531     i_result = pthread_cond_wait( &p_condvar->cond, &p_mutex->mutex );
532 #   endif
533
534     if ( i_result )
535     {
536         i_thread = CAST_PTHREAD_TO_INT(pthread_self());
537         psz_error = strerror(i_result);
538     }
539
540 #elif defined( HAVE_CTHREADS_H )
541     condition_wait( (condition_t)p_condvar, (mutex_t)p_mutex );
542     i_result = 0;
543
544 #endif
545
546     if( i_result )
547     {
548         msg_Err( p_condvar->p_this,
549                  "thread %li: cond_wait failed at %s:%d (%d:%s)",
550                  i_thread, psz_file, i_line, i_result, psz_error );
551     }
552
553     return i_result;
554 }
555
556
557 /*****************************************************************************
558  * vlc_cond_timedwait: wait until condition completion or expiration
559  *****************************************************************************/
560 #define vlc_cond_timedwait( P_COND, P_MUTEX, DEADLINE )                      \
561     __vlc_cond_timedwait( __FILE__, __LINE__, P_COND, P_MUTEX, DEADLINE  )
562
563 static inline int __vlc_cond_timedwait( const char * psz_file, int i_line,
564                                         vlc_cond_t *p_condvar,
565                                         vlc_mutex_t *p_mutex,
566                                         mtime_t deadline )
567 {
568     int i_res;
569     unsigned long int i_thread = 0;
570     const char * psz_error = "";
571
572 #if defined( PTH_INIT_IN_PTH_H )
573 #   error Unimplemented
574 #elif defined( ST_INIT_IN_ST_H )
575 #   error Unimplemented
576 #elif defined( UNDER_CE )
577 #   error Unimplemented
578 #elif defined( WIN32 )
579 #   error Unimplemented FIXME FIXME
580
581 #elif defined( HAVE_KERNEL_SCHEDULER_H )
582 #   error Unimplemented
583 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
584     lldiv_t d = lldiv( deadline, 1000000 );
585     struct timespec ts = { d.quot, d.rem * 1000 };
586
587     i_res = pthread_cond_timedwait( &p_condvar->cond, &p_mutex->mutex, &ts );
588     if( i_res == ETIMEDOUT )
589         i_res = 0; /* this error is perfectly normal */
590     else
591     if ( i_res ) /* other errors = bug */
592     {
593         i_thread = CAST_PTHREAD_TO_INT(pthread_self());
594         psz_error = strerror(i_res);
595     }
596
597 #elif defined( HAVE_CTHREADS_H )
598 #   error Unimplemented
599 #endif
600
601     if( i_res )
602     {
603         msg_Err( p_condvar->p_this,
604                  "thread %li: cond_wait failed at %s:%d (%d:%s)",
605                  i_thread, psz_file, i_line, i_res, psz_error );
606     }
607
608     return i_res;
609 }
610
611 /*****************************************************************************
612  * vlc_cond_destroy: destroy a condition
613  *****************************************************************************/
614 #define vlc_cond_destroy( P_COND )                                          \
615     __vlc_cond_destroy( __FILE__, __LINE__, P_COND )
616
617 /*****************************************************************************
618  * vlc_threadvar_create: create a thread-local variable
619  *****************************************************************************/
620 #define vlc_threadvar_create( PTHIS, P_TLS )                                 \
621    __vlc_threadvar_create( PTHIS, P_TLS )
622
623 /*****************************************************************************
624  * vlc_threadvar_set: create: set the value of a thread-local variable
625  *****************************************************************************/
626 static inline int vlc_threadvar_set( vlc_threadvar_t * p_tls, void *p_value )
627 {
628     int i_ret;
629
630 #if defined( PTH_INIT_IN_PTH_H )
631     return pth_key_setdata( p_tls->handle, p_value );
632 #elif  defined( ST_INIT_IN_ST_H )
633     return st_thread_setspecific( p_tls->handle, p_value );
634 #elif defined( HAVE_KERNEL_SCHEDULER_H )
635     return -1;
636
637 #elif defined( UNDER_CE ) || defined( WIN32 )
638     i_ret = ( TlsSetValue( p_tls->handle, p_value ) != 0 );
639
640 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
641     i_ret = pthread_setspecific( p_tls->handle, p_value );
642
643 #elif defined( HAVE_CTHREADS_H )
644     i_ret = cthread_setspecific( p_tls->handle, p_value );
645 #endif
646
647     return i_ret;
648 }
649
650 /*****************************************************************************
651  * vlc_threadvar_get: create: get the value of a thread-local variable
652  *****************************************************************************/
653 static inline void* vlc_threadvar_get( vlc_threadvar_t * p_tls )
654 {
655     void* p_ret;
656
657 #if defined( PTH_INIT_IN_PTH_H )
658     p_ret = pth_key_getdata( p_handle->key );
659 #elif defined( ST_INIT_IN_ST_H )
660     p_ret = st_thread_getspecific( p_handle->key );
661 #elif defined( HAVE_KERNEL_SCHEDULER_H )
662     p_ret = NULL;
663 #elif defined( UNDER_CE ) || defined( WIN32 )
664     p_ret = TlsGetValue( p_tls->handle );
665
666 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
667     p_ret = pthread_getspecific( p_tls->handle );
668
669 #elif defined( HAVE_CTHREADS_H )
670     if ( !cthread_getspecific( p_tls->handle, &p_ret ) )
671     {
672         p_ret = NULL;
673     }
674 #endif
675
676     return p_ret;
677 }
678
679 /*****************************************************************************
680  * vlc_thread_create: create a thread
681  *****************************************************************************/
682 #define vlc_thread_create( P_THIS, PSZ_NAME, FUNC, PRIORITY, WAIT )         \
683     __vlc_thread_create( VLC_OBJECT(P_THIS), __FILE__, __LINE__, PSZ_NAME, (void * ( * ) ( void * ))FUNC, PRIORITY, WAIT )
684
685 /*****************************************************************************
686  * vlc_thread_set_priority: set the priority of the calling thread
687  *****************************************************************************/
688 #define vlc_thread_set_priority( P_THIS, PRIORITY )                         \
689     __vlc_thread_set_priority( VLC_OBJECT(P_THIS), __FILE__, __LINE__, PRIORITY )
690
691 /*****************************************************************************
692  * vlc_thread_ready: tell the parent thread we were successfully spawned
693  *****************************************************************************/
694 #define vlc_thread_ready( P_THIS )                                          \
695     __vlc_thread_ready( VLC_OBJECT(P_THIS) )
696
697 /*****************************************************************************
698  * vlc_thread_join: wait until a thread exits
699  *****************************************************************************/
700 #define vlc_thread_join( P_THIS )                                           \
701     __vlc_thread_join( VLC_OBJECT(P_THIS), __FILE__, __LINE__ )
702
703 #endif