1 /*****************************************************************************
2 * threads.c : threads implementation for the VideoLAN client
3 *****************************************************************************
4 * Copyright (C) 1999-2007 the VideoLAN team
7 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8 * Samuel Hocevar <sam@zoy.org>
9 * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
32 #define VLC_THREADS_UNINITIALIZED 0
33 #define VLC_THREADS_PENDING 1
34 #define VLC_THREADS_ERROR 2
35 #define VLC_THREADS_READY 3
37 /*****************************************************************************
38 * Global mutex for lazy initialization of the threads system
39 *****************************************************************************/
40 static volatile unsigned i_initializations = 0;
41 static volatile int i_status = VLC_THREADS_UNINITIALIZED;
42 static vlc_object_t *p_root;
44 #if defined( PTH_INIT_IN_PTH_H )
45 #elif defined( ST_INIT_IN_ST_H )
46 #elif defined( UNDER_CE )
47 #elif defined( WIN32 )
48 static SIGNALOBJECTANDWAIT pf_SignalObjectAndWait = NULL;
49 static vlc_bool_t b_fast_mutex = 0;
50 static int i_win9x_cv = 0;
51 #elif defined( HAVE_KERNEL_SCHEDULER_H )
52 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
53 static pthread_mutex_t once_mutex = PTHREAD_MUTEX_INITIALIZER;
54 #elif defined( HAVE_CTHREADS_H )
57 vlc_threadvar_t msg_context_global_key;
59 /*****************************************************************************
60 * vlc_threads_init: initialize threads system
61 *****************************************************************************
62 * This function requires lazy initialization of a global lock in order to
63 * keep the library really thread-safe. Some architectures don't support this
64 * and thus do not guarantee the complete reentrancy.
65 *****************************************************************************/
66 int __vlc_threads_init( vlc_object_t *p_this )
68 libvlc_global_data_t *p_libvlc_global = (libvlc_global_data_t *)p_this;
69 int i_ret = VLC_SUCCESS;
71 /* If we have lazy mutex initialization, use it. Otherwise, we just
72 * hope nothing wrong happens. */
73 #if defined( PTH_INIT_IN_PTH_H )
74 #elif defined( ST_INIT_IN_ST_H )
75 #elif defined( UNDER_CE )
76 #elif defined( WIN32 )
77 if( IsDebuggerPresent() )
79 /* SignalObjectAndWait() API is problematic under a debugger */
80 b_fast_mutex = VLC_TRUE;
85 b_fast_mutex = VLC_FALSE;
88 #elif defined( HAVE_KERNEL_SCHEDULER_H )
89 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
90 pthread_mutex_lock( &once_mutex );
91 #elif defined( HAVE_CTHREADS_H )
94 if( i_status == VLC_THREADS_UNINITIALIZED )
96 i_status = VLC_THREADS_PENDING;
98 /* We should be safe now. Do all the initialization stuff we want. */
99 p_libvlc_global->b_ready = VLC_FALSE;
101 #if defined( PTH_INIT_IN_PTH_H )
102 i_ret = ( pth_init() == FALSE );
104 #elif defined( ST_INIT_IN_ST_H )
107 #elif defined( UNDER_CE )
108 /* Nothing to initialize */
110 #elif defined( WIN32 )
111 /* Dynamically get the address of SignalObjectAndWait */
112 if( GetVersion() < 0x80000000 )
116 /* We are running on NT/2K/XP, we can use SignalObjectAndWait */
117 hInstLib = LoadLibrary( "kernel32" );
120 pf_SignalObjectAndWait =
121 (SIGNALOBJECTANDWAIT)GetProcAddress( hInstLib,
122 "SignalObjectAndWait" );
126 #elif defined( HAVE_KERNEL_SCHEDULER_H )
127 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
128 #elif defined( HAVE_CTHREADS_H )
131 p_root = vlc_object_create( p_libvlc_global, VLC_OBJECT_GLOBAL );
137 i_status = VLC_THREADS_ERROR;
142 i_status = VLC_THREADS_READY;
145 vlc_threadvar_create( p_root, &msg_context_global_key );
149 /* Just increment the initialization count */
153 /* If we have lazy mutex initialization support, unlock the mutex;
154 * otherwize, do a naive wait loop. */
155 #if defined( PTH_INIT_IN_PTH_H )
156 while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
157 #elif defined( ST_INIT_IN_ST_H )
158 while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
159 #elif defined( UNDER_CE )
160 while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
161 #elif defined( WIN32 )
162 while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
163 #elif defined( HAVE_KERNEL_SCHEDULER_H )
164 while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
165 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
166 pthread_mutex_unlock( &once_mutex );
167 #elif defined( HAVE_CTHREADS_H )
168 while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
171 if( i_status != VLC_THREADS_READY )
179 /*****************************************************************************
180 * vlc_threads_end: stop threads system
181 *****************************************************************************
182 * FIXME: This function is far from being threadsafe.
183 *****************************************************************************/
184 int __vlc_threads_end( vlc_object_t *p_this )
187 #if defined( PTH_INIT_IN_PTH_H )
188 #elif defined( ST_INIT_IN_ST_H )
189 #elif defined( UNDER_CE )
190 #elif defined( WIN32 )
191 #elif defined( HAVE_KERNEL_SCHEDULER_H )
192 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
193 pthread_mutex_lock( &once_mutex );
194 #elif defined( HAVE_CTHREADS_H )
197 if( i_initializations == 0 )
201 if( i_initializations == 0 )
203 i_status = VLC_THREADS_UNINITIALIZED;
204 vlc_object_destroy( p_root );
207 #if defined( PTH_INIT_IN_PTH_H )
208 if( i_initializations == 0 )
210 return ( pth_kill() == FALSE );
213 #elif defined( ST_INIT_IN_ST_H )
214 #elif defined( UNDER_CE )
215 #elif defined( WIN32 )
216 #elif defined( HAVE_KERNEL_SCHEDULER_H )
217 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
218 pthread_mutex_unlock( &once_mutex );
219 #elif defined( HAVE_CTHREADS_H )
224 /*****************************************************************************
225 * vlc_mutex_init: initialize a mutex
226 *****************************************************************************/
227 int __vlc_mutex_init( vlc_object_t *p_this, vlc_mutex_t *p_mutex )
229 p_mutex->p_this = p_this;
231 #if defined( PTH_INIT_IN_PTH_H )
232 return ( pth_mutex_init( &p_mutex->mutex ) == FALSE );
234 #elif defined( ST_INIT_IN_ST_H )
235 p_mutex->mutex = st_mutex_new();
236 return ( p_mutex->mutex == NULL ) ? errno : 0;
238 #elif defined( UNDER_CE )
239 InitializeCriticalSection( &p_mutex->csection );
242 #elif defined( WIN32 )
243 /* We use mutexes on WinNT/2K/XP because we can use the SignalObjectAndWait
244 * function and have a 100% correct vlc_cond_wait() implementation.
245 * As this function is not available on Win9x, we can use the faster
246 * CriticalSections */
247 if( pf_SignalObjectAndWait && !b_fast_mutex )
249 /* We are running on NT/2K/XP, we can use SignalObjectAndWait */
250 p_mutex->mutex = CreateMutex( 0, FALSE, 0 );
251 return ( p_mutex->mutex != NULL ? 0 : 1 );
255 p_mutex->mutex = NULL;
256 InitializeCriticalSection( &p_mutex->csection );
260 #elif defined( HAVE_KERNEL_SCHEDULER_H )
261 /* check the arguments and whether it's already been initialized */
262 if( p_mutex == NULL )
267 if( p_mutex->init == 9999 )
272 p_mutex->lock = create_sem( 1, "BeMutex" );
273 if( p_mutex->lock < B_NO_ERROR )
278 p_mutex->init = 9999;
281 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
282 # if defined(DEBUG) && defined(SYS_LINUX)
284 /* Create error-checking mutex to detect problems more easily. */
285 pthread_mutexattr_t attr;
288 pthread_mutexattr_init( &attr );
289 pthread_mutexattr_setkind_np( &attr, PTHREAD_MUTEX_ERRORCHECK_NP );
290 i_result = pthread_mutex_init( &p_mutex->mutex, &attr );
291 pthread_mutexattr_destroy( &attr );
295 return pthread_mutex_init( &p_mutex->mutex, NULL );
297 #elif defined( HAVE_CTHREADS_H )
298 mutex_init( p_mutex );
304 /*****************************************************************************
305 * vlc_mutex_destroy: destroy a mutex, inner version
306 *****************************************************************************/
307 int __vlc_mutex_destroy( const char * psz_file, int i_line, vlc_mutex_t *p_mutex )
310 /* In case of error : */
312 const char * psz_error = "";
314 #if defined( PTH_INIT_IN_PTH_H )
317 #elif defined( ST_INIT_IN_ST_H )
318 i_result = st_mutex_destroy( p_mutex->mutex );
320 #elif defined( UNDER_CE )
321 DeleteCriticalSection( &p_mutex->csection );
324 #elif defined( WIN32 )
327 CloseHandle( p_mutex->mutex );
331 DeleteCriticalSection( &p_mutex->csection );
335 #elif defined( HAVE_KERNEL_SCHEDULER_H )
336 if( p_mutex->init == 9999 )
338 delete_sem( p_mutex->lock );
344 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
345 i_result = pthread_mutex_destroy( &p_mutex->mutex );
348 i_thread = CAST_PTHREAD_TO_INT(pthread_self());
349 psz_error = strerror(i_result);
352 #elif defined( HAVE_CTHREADS_H )
359 msg_Err( p_mutex->p_this,
360 "thread %d: mutex_destroy failed at %s:%d (%d:%s)",
361 i_thread, psz_file, i_line, i_result, psz_error );
366 /*****************************************************************************
367 * vlc_cond_init: initialize a condition
368 *****************************************************************************/
369 int __vlc_cond_init( vlc_object_t *p_this, vlc_cond_t *p_condvar )
371 p_condvar->p_this = p_this;
373 #if defined( PTH_INIT_IN_PTH_H )
374 return ( pth_cond_init( &p_condvar->cond ) == FALSE );
376 #elif defined( ST_INIT_IN_ST_H )
377 p_condvar->cond = st_cond_new();
378 return ( p_condvar->cond == NULL ) ? errno : 0;
380 #elif defined( UNDER_CE )
381 /* Initialize counter */
382 p_condvar->i_waiting_threads = 0;
384 /* Create an auto-reset event. */
385 p_condvar->event = CreateEvent( NULL, /* no security */
386 FALSE, /* auto-reset event */
387 FALSE, /* start non-signaled */
388 NULL ); /* unnamed */
389 return !p_condvar->event;
391 #elif defined( WIN32 )
392 /* Initialize counter */
393 p_condvar->i_waiting_threads = 0;
396 p_condvar->i_win9x_cv = i_win9x_cv;
397 p_condvar->SignalObjectAndWait = pf_SignalObjectAndWait;
399 if( (p_condvar->SignalObjectAndWait && !b_fast_mutex)
400 || p_condvar->i_win9x_cv == 0 )
402 /* Create an auto-reset event. */
403 p_condvar->event = CreateEvent( NULL, /* no security */
404 FALSE, /* auto-reset event */
405 FALSE, /* start non-signaled */
406 NULL ); /* unnamed */
408 p_condvar->semaphore = NULL;
409 return !p_condvar->event;
413 p_condvar->semaphore = CreateSemaphore( NULL, /* no security */
414 0, /* initial count */
415 0x7fffffff, /* max count */
416 NULL ); /* unnamed */
418 if( p_condvar->i_win9x_cv == 1 )
419 /* Create a manual-reset event initially signaled. */
420 p_condvar->event = CreateEvent( NULL, TRUE, TRUE, NULL );
422 /* Create a auto-reset event. */
423 p_condvar->event = CreateEvent( NULL, FALSE, FALSE, NULL );
425 InitializeCriticalSection( &p_condvar->csection );
427 return !p_condvar->semaphore || !p_condvar->event;
430 #elif defined( HAVE_KERNEL_SCHEDULER_H )
436 if( p_condvar->init == 9999 )
441 p_condvar->thread = -1;
442 p_condvar->init = 9999;
445 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
446 return pthread_cond_init( &p_condvar->cond, NULL );
448 #elif defined( HAVE_CTHREADS_H )
449 /* condition_init() */
450 spin_lock_init( &p_condvar->lock );
451 cthread_queue_init( &p_condvar->queue );
453 p_condvar->implications = 0;
460 /*****************************************************************************
461 * vlc_cond_destroy: destroy a condition, inner version
462 *****************************************************************************/
463 int __vlc_cond_destroy( const char * psz_file, int i_line, vlc_cond_t *p_condvar )
466 /* In case of error : */
468 const char * psz_error = "";
470 #if defined( PTH_INIT_IN_PTH_H )
473 #elif defined( ST_INIT_IN_ST_H )
474 i_result = st_cond_destroy( p_condvar->cond );
476 #elif defined( UNDER_CE )
477 i_result = !CloseHandle( p_condvar->event );
479 #elif defined( WIN32 )
480 if( !p_condvar->semaphore )
481 i_result = !CloseHandle( p_condvar->event );
483 i_result = !CloseHandle( p_condvar->event )
484 || !CloseHandle( p_condvar->semaphore );
486 if( p_condvar->semaphore != NULL )
487 DeleteCriticalSection( &p_condvar->csection );
489 #elif defined( HAVE_KERNEL_SCHEDULER_H )
493 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
494 i_result = pthread_cond_destroy( &p_condvar->cond );
497 i_thread = CAST_PTHREAD_TO_INT(pthread_self());
498 psz_error = strerror(i_result);
501 #elif defined( HAVE_CTHREADS_H )
508 msg_Err( p_condvar->p_this,
509 "thread %d: cond_destroy failed at %s:%d (%d:%s)",
510 i_thread, psz_file, i_line, i_result, psz_error );
515 /*****************************************************************************
516 * vlc_tls_create: create a thread-local variable
517 *****************************************************************************/
518 int __vlc_threadvar_create( vlc_object_t *p_this, vlc_threadvar_t *p_tls )
522 #if defined( PTH_INIT_IN_PTH_H )
523 i_ret = pth_key_create( &p_tls->handle, NULL );
524 #elif defined( HAVE_KERNEL_SCHEDULER_H )
525 msg_Err( p_this, "TLS not implemented" );
527 #elif defined( ST_INIT_IN_ST_H )
528 i_ret = st_key_create( &p_tls->handle, NULL );
529 #elif defined( UNDER_CE ) || defined( WIN32 )
530 #elif defined( WIN32 )
531 p_tls->handle = TlsAlloc();
532 i_ret = !( p_tls->handle == 0xFFFFFFFF );
534 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
535 i_ret = pthread_key_create( &p_tls->handle, NULL );
536 #elif defined( HAVE_CTHREADS_H )
537 i_ret = cthread_keycreate( &p_tls-handle );
542 /*****************************************************************************
543 * vlc_thread_create: create a thread, inner version
544 *****************************************************************************
545 * Note that i_priority is only taken into account on platforms supporting
546 * userland real-time priority threads.
547 *****************************************************************************/
548 int __vlc_thread_create( vlc_object_t *p_this, const char * psz_file, int i_line,
549 const char *psz_name, void * ( *func ) ( void * ),
550 int i_priority, vlc_bool_t b_wait )
553 void *p_data = (void *)p_this;
555 vlc_mutex_lock( &p_this->object_lock );
557 #if defined( PTH_INIT_IN_PTH_H )
558 p_this->thread_id = pth_spawn( PTH_ATTR_DEFAULT, func, p_data );
559 i_ret = p_this->thread_id == NULL;
561 #elif defined( ST_INIT_IN_ST_H )
562 p_this->thread_id = st_thread_create( func, p_data, 1, 0 );
565 #elif defined( WIN32 ) || defined( UNDER_CE )
568 /* When using the MSVCRT C library you have to use the _beginthreadex
569 * function instead of CreateThread, otherwise you'll end up with
570 * memory leaks and the signal functions not working (see Microsoft
571 * Knowledge Base, article 104641) */
573 #if defined( UNDER_CE )
574 (HANDLE)CreateThread( NULL, 0, (PTHREAD_START) func,
575 p_data, 0, &threadID );
577 (HANDLE)_beginthreadex( NULL, 0, (PTHREAD_START) func,
578 p_data, 0, &threadID );
582 if( p_this->thread_id && i_priority )
584 if( !SetThreadPriority(p_this->thread_id, i_priority) )
586 msg_Warn( p_this, "couldn't set a faster priority" );
591 i_ret = ( p_this->thread_id ? 0 : 1 );
593 #elif defined( HAVE_KERNEL_SCHEDULER_H )
594 p_this->thread_id = spawn_thread( (thread_func)func, psz_name,
595 i_priority, p_data );
596 i_ret = resume_thread( p_this->thread_id );
598 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
599 i_ret = pthread_create( &p_this->thread_id, NULL, func, p_data );
602 if( config_GetInt( p_this, "rt-priority" ) )
605 int i_error, i_policy;
606 struct sched_param param;
608 memset( ¶m, 0, sizeof(struct sched_param) );
609 if( config_GetType( p_this, "rt-offset" ) )
611 i_priority += config_GetInt( p_this, "rt-offset" );
613 if( i_priority <= 0 )
615 param.sched_priority = (-1) * i_priority;
616 i_policy = SCHED_OTHER;
620 param.sched_priority = i_priority;
623 if( (i_error = pthread_setschedparam( p_this->thread_id,
624 i_policy, ¶m )) )
626 msg_Warn( p_this, "couldn't set thread priority (%s:%d): %s",
627 psz_file, i_line, strerror(i_error) );
638 #elif defined( HAVE_CTHREADS_H )
639 p_this->thread_id = cthread_fork( (cthread_fn_t)func, (any_t)p_data );
648 msg_Dbg( p_this, "waiting for thread completion" );
649 vlc_cond_wait( &p_this->object_wait, &p_this->object_lock );
652 p_this->b_thread = 1;
654 msg_Dbg( p_this, "thread %u (%s) created at priority %d (%s:%d)",
655 (unsigned int)p_this->thread_id, psz_name, i_priority,
658 vlc_mutex_unlock( &p_this->object_lock );
662 msg_Err( p_this, "%s thread could not be created at %s:%d (%s)",
663 psz_name, psz_file, i_line, strerror(i_ret) );
664 vlc_mutex_unlock( &p_this->object_lock );
670 /*****************************************************************************
671 * vlc_thread_set_priority: set the priority of the current thread when we
672 * couldn't set it in vlc_thread_create (for instance for the main thread)
673 *****************************************************************************/
674 int __vlc_thread_set_priority( vlc_object_t *p_this, const char * psz_file,
675 int i_line, int i_priority )
677 #if defined( PTH_INIT_IN_PTH_H ) || defined( ST_INIT_IN_ST_H )
678 #elif defined( WIN32 ) || defined( UNDER_CE )
679 if( !SetThreadPriority(GetCurrentThread(), i_priority) )
681 msg_Warn( p_this, "couldn't set a faster priority" );
685 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
687 if( config_GetInt( p_this, "rt-priority" ) )
690 int i_error, i_policy;
691 struct sched_param param;
693 memset( ¶m, 0, sizeof(struct sched_param) );
694 if( config_GetType( p_this, "rt-offset" ) )
696 i_priority += config_GetInt( p_this, "rt-offset" );
698 if( i_priority <= 0 )
700 param.sched_priority = (-1) * i_priority;
701 i_policy = SCHED_OTHER;
705 param.sched_priority = i_priority;
708 if( !p_this->thread_id )
709 p_this->thread_id = pthread_self();
710 if( (i_error = pthread_setschedparam( p_this->thread_id,
711 i_policy, ¶m )) )
713 msg_Warn( p_this, "couldn't set thread priority (%s:%d): %s",
714 psz_file, i_line, strerror(i_error) );
723 /*****************************************************************************
724 * vlc_thread_ready: tell the parent thread we were successfully spawned
725 *****************************************************************************/
726 void __vlc_thread_ready( vlc_object_t *p_this )
728 vlc_mutex_lock( &p_this->object_lock );
729 vlc_cond_signal( &p_this->object_wait );
730 vlc_mutex_unlock( &p_this->object_lock );
733 /*****************************************************************************
734 * vlc_thread_join: wait until a thread exits, inner version
735 *****************************************************************************/
736 void __vlc_thread_join( vlc_object_t *p_this, const char * psz_file, int i_line )
740 #if defined( PTH_INIT_IN_PTH_H )
741 i_ret = ( pth_join( p_this->thread_id, NULL ) == FALSE );
743 #elif defined( ST_INIT_IN_ST_H )
744 i_ret = st_thread_join( p_this->thread_id, NULL );
746 #elif defined( UNDER_CE ) || defined( WIN32 )
748 BOOL (WINAPI *OurGetThreadTimes)( HANDLE, FILETIME*, FILETIME*,
749 FILETIME*, FILETIME* );
750 FILETIME create_ft, exit_ft, kernel_ft, user_ft;
751 int64_t real_time, kernel_time, user_time;
753 WaitForSingleObject( p_this->thread_id, INFINITE );
755 #if defined( UNDER_CE )
756 hmodule = GetModuleHandle( _T("COREDLL") );
758 hmodule = GetModuleHandle( _T("KERNEL32") );
760 OurGetThreadTimes = (BOOL (WINAPI*)( HANDLE, FILETIME*, FILETIME*,
761 FILETIME*, FILETIME* ))
762 GetProcAddress( hmodule, _T("GetThreadTimes") );
764 if( OurGetThreadTimes &&
765 OurGetThreadTimes( p_this->thread_id,
766 &create_ft, &exit_ft, &kernel_ft, &user_ft ) )
769 ((((int64_t)exit_ft.dwHighDateTime)<<32)| exit_ft.dwLowDateTime) -
770 ((((int64_t)create_ft.dwHighDateTime)<<32)| create_ft.dwLowDateTime);
774 ((((int64_t)kernel_ft.dwHighDateTime)<<32)|
775 kernel_ft.dwLowDateTime) / 10;
778 ((((int64_t)user_ft.dwHighDateTime)<<32)|
779 user_ft.dwLowDateTime) / 10;
781 msg_Dbg( p_this, "thread times: "
782 "real "I64Fd"m%fs, kernel "I64Fd"m%fs, user "I64Fd"m%fs",
783 real_time/60/1000000,
784 (double)((real_time%(60*1000000))/1000000.0),
785 kernel_time/60/1000000,
786 (double)((kernel_time%(60*1000000))/1000000.0),
787 user_time/60/1000000,
788 (double)((user_time%(60*1000000))/1000000.0) );
790 CloseHandle( p_this->thread_id );
792 #elif defined( HAVE_KERNEL_SCHEDULER_H )
794 wait_for_thread( p_this->thread_id, &exit_value );
796 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
797 i_ret = pthread_join( p_this->thread_id, NULL );
799 #elif defined( HAVE_CTHREADS_H )
800 cthread_join( p_this->thread_id );
807 msg_Err( p_this, "thread_join(%u) failed at %s:%d (%s)",
808 (unsigned int)p_this->thread_id, psz_file, i_line,
813 msg_Dbg( p_this, "thread %u joined (%s:%d)",
814 (unsigned int)p_this->thread_id, psz_file, i_line );
817 p_this->b_thread = 0;