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 *****************************************************************************/
31 #define VLC_THREADS_UNINITIALIZED 0
32 #define VLC_THREADS_PENDING 1
33 #define VLC_THREADS_ERROR 2
34 #define VLC_THREADS_READY 3
36 /*****************************************************************************
37 * Global mutex for lazy initialization of the threads system
38 *****************************************************************************/
39 static volatile unsigned i_initializations = 0;
40 static volatile int i_status = VLC_THREADS_UNINITIALIZED;
41 static vlc_object_t *p_root;
43 #if defined( PTH_INIT_IN_PTH_H )
44 #elif defined( ST_INIT_IN_ST_H )
45 #elif defined( UNDER_CE )
46 #elif defined( WIN32 )
47 #elif defined( HAVE_KERNEL_SCHEDULER_H )
48 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
49 static pthread_mutex_t once_mutex = PTHREAD_MUTEX_INITIALIZER;
50 #elif defined( HAVE_CTHREADS_H )
53 vlc_threadvar_t msg_context_global_key;
55 /*****************************************************************************
56 * vlc_threads_init: initialize threads system
57 *****************************************************************************
58 * This function requires lazy initialization of a global lock in order to
59 * keep the library really thread-safe. Some architectures don't support this
60 * and thus do not guarantee the complete reentrancy.
61 *****************************************************************************/
62 int __vlc_threads_init( vlc_object_t *p_this )
64 libvlc_global_data_t *p_libvlc_global = (libvlc_global_data_t *)p_this;
65 int i_ret = VLC_SUCCESS;
67 /* If we have lazy mutex initialization, use it. Otherwise, we just
68 * hope nothing wrong happens. */
69 #if defined( PTH_INIT_IN_PTH_H )
70 #elif defined( ST_INIT_IN_ST_H )
71 #elif defined( UNDER_CE )
72 #elif defined( WIN32 )
73 #elif defined( HAVE_KERNEL_SCHEDULER_H )
74 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
75 pthread_mutex_lock( &once_mutex );
76 #elif defined( HAVE_CTHREADS_H )
79 if( i_status == VLC_THREADS_UNINITIALIZED )
81 i_status = VLC_THREADS_PENDING;
83 /* We should be safe now. Do all the initialization stuff we want. */
84 p_libvlc_global->b_ready = VLC_FALSE;
86 #if defined( PTH_INIT_IN_PTH_H )
87 i_ret = ( pth_init() == FALSE );
89 #elif defined( ST_INIT_IN_ST_H )
92 #elif defined( UNDER_CE )
93 /* Nothing to initialize */
95 #elif defined( WIN32 )
96 /* Dynamically get the address of SignalObjectAndWait */
97 if( GetVersion() < 0x80000000 )
101 /* We are running on NT/2K/XP, we can use SignalObjectAndWait */
102 hInstLib = LoadLibrary( "kernel32" );
105 p_libvlc_global->SignalObjectAndWait =
106 (SIGNALOBJECTANDWAIT)GetProcAddress( hInstLib,
107 "SignalObjectAndWait" );
112 p_libvlc_global->SignalObjectAndWait = NULL;
115 p_libvlc_global->b_fast_mutex = 0;
116 p_libvlc_global->i_win9x_cv = 0;
118 #elif defined( HAVE_KERNEL_SCHEDULER_H )
119 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
120 #elif defined( HAVE_CTHREADS_H )
123 p_root = vlc_object_create( p_libvlc_global, VLC_OBJECT_GLOBAL );
129 i_status = VLC_THREADS_ERROR;
134 i_status = VLC_THREADS_READY;
137 vlc_threadvar_create( p_root, &msg_context_global_key );
141 /* Just increment the initialization count */
145 /* If we have lazy mutex initialization support, unlock the mutex;
146 * otherwize, do a naive wait loop. */
147 #if defined( PTH_INIT_IN_PTH_H )
148 while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
149 #elif defined( ST_INIT_IN_ST_H )
150 while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
151 #elif defined( UNDER_CE )
152 while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
153 #elif defined( WIN32 )
154 while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
155 #elif defined( HAVE_KERNEL_SCHEDULER_H )
156 while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
157 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
158 pthread_mutex_unlock( &once_mutex );
159 #elif defined( HAVE_CTHREADS_H )
160 while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
163 if( i_status != VLC_THREADS_READY )
171 /*****************************************************************************
172 * vlc_threads_end: stop threads system
173 *****************************************************************************
174 * FIXME: This function is far from being threadsafe.
175 *****************************************************************************/
176 int __vlc_threads_end( vlc_object_t *p_this )
179 #if defined( PTH_INIT_IN_PTH_H )
180 #elif defined( ST_INIT_IN_ST_H )
181 #elif defined( UNDER_CE )
182 #elif defined( WIN32 )
183 #elif defined( HAVE_KERNEL_SCHEDULER_H )
184 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
185 pthread_mutex_lock( &once_mutex );
186 #elif defined( HAVE_CTHREADS_H )
189 if( i_initializations == 0 )
193 if( i_initializations == 0 )
195 i_status = VLC_THREADS_UNINITIALIZED;
196 vlc_object_destroy( p_root );
199 #if defined( PTH_INIT_IN_PTH_H )
200 if( i_initializations == 0 )
202 return ( pth_kill() == FALSE );
205 #elif defined( ST_INIT_IN_ST_H )
206 #elif defined( UNDER_CE )
207 #elif defined( WIN32 )
208 #elif defined( HAVE_KERNEL_SCHEDULER_H )
209 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
210 pthread_mutex_unlock( &once_mutex );
211 #elif defined( HAVE_CTHREADS_H )
216 /*****************************************************************************
217 * vlc_mutex_init: initialize a mutex
218 *****************************************************************************/
219 int __vlc_mutex_init( vlc_object_t *p_this, vlc_mutex_t *p_mutex )
221 p_mutex->p_this = p_this;
223 #if defined( PTH_INIT_IN_PTH_H )
224 return ( pth_mutex_init( &p_mutex->mutex ) == FALSE );
226 #elif defined( ST_INIT_IN_ST_H )
227 p_mutex->mutex = st_mutex_new();
228 return ( p_mutex->mutex == NULL ) ? errno : 0;
230 #elif defined( UNDER_CE )
231 InitializeCriticalSection( &p_mutex->csection );
234 #elif defined( WIN32 )
235 /* We use mutexes on WinNT/2K/XP because we can use the SignalObjectAndWait
236 * function and have a 100% correct vlc_cond_wait() implementation.
237 * As this function is not available on Win9x, we can use the faster
238 * CriticalSections */
239 if( p_this->p_libvlc_global->SignalObjectAndWait &&
240 !p_this->p_libvlc_global->b_fast_mutex )
242 /* We are running on NT/2K/XP, we can use SignalObjectAndWait */
243 p_mutex->mutex = CreateMutex( 0, FALSE, 0 );
244 return ( p_mutex->mutex != NULL ? 0 : 1 );
248 p_mutex->mutex = NULL;
249 InitializeCriticalSection( &p_mutex->csection );
253 #elif defined( HAVE_KERNEL_SCHEDULER_H )
254 /* check the arguments and whether it's already been initialized */
255 if( p_mutex == NULL )
260 if( p_mutex->init == 9999 )
265 p_mutex->lock = create_sem( 1, "BeMutex" );
266 if( p_mutex->lock < B_NO_ERROR )
271 p_mutex->init = 9999;
274 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
275 # if defined(DEBUG) && defined(SYS_LINUX)
277 /* Create error-checking mutex to detect problems more easily. */
278 pthread_mutexattr_t attr;
281 pthread_mutexattr_init( &attr );
282 pthread_mutexattr_setkind_np( &attr, PTHREAD_MUTEX_ERRORCHECK_NP );
283 i_result = pthread_mutex_init( &p_mutex->mutex, &attr );
284 pthread_mutexattr_destroy( &attr );
288 return pthread_mutex_init( &p_mutex->mutex, NULL );
290 #elif defined( HAVE_CTHREADS_H )
291 mutex_init( p_mutex );
297 /*****************************************************************************
298 * vlc_mutex_destroy: destroy a mutex, inner version
299 *****************************************************************************/
300 int __vlc_mutex_destroy( const char * psz_file, int i_line, vlc_mutex_t *p_mutex )
303 /* In case of error : */
305 const char * psz_error = "";
307 #if defined( PTH_INIT_IN_PTH_H )
310 #elif defined( ST_INIT_IN_ST_H )
311 i_result = st_mutex_destroy( p_mutex->mutex );
313 #elif defined( UNDER_CE )
314 DeleteCriticalSection( &p_mutex->csection );
317 #elif defined( WIN32 )
320 CloseHandle( p_mutex->mutex );
324 DeleteCriticalSection( &p_mutex->csection );
328 #elif defined( HAVE_KERNEL_SCHEDULER_H )
329 if( p_mutex->init == 9999 )
331 delete_sem( p_mutex->lock );
337 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
338 i_result = pthread_mutex_destroy( &p_mutex->mutex );
341 i_thread = CAST_PTHREAD_TO_INT(pthread_self());
342 psz_error = strerror(i_result);
345 #elif defined( HAVE_CTHREADS_H )
352 msg_Err( p_mutex->p_this,
353 "thread %d: mutex_destroy failed at %s:%d (%d:%s)",
354 i_thread, psz_file, i_line, i_result, psz_error );
359 /*****************************************************************************
360 * vlc_cond_init: initialize a condition
361 *****************************************************************************/
362 int __vlc_cond_init( vlc_object_t *p_this, vlc_cond_t *p_condvar )
364 p_condvar->p_this = p_this;
366 #if defined( PTH_INIT_IN_PTH_H )
367 return ( pth_cond_init( &p_condvar->cond ) == FALSE );
369 #elif defined( ST_INIT_IN_ST_H )
370 p_condvar->cond = st_cond_new();
371 return ( p_condvar->cond == NULL ) ? errno : 0;
373 #elif defined( UNDER_CE )
374 /* Initialize counter */
375 p_condvar->i_waiting_threads = 0;
377 /* Create an auto-reset event. */
378 p_condvar->event = CreateEvent( NULL, /* no security */
379 FALSE, /* auto-reset event */
380 FALSE, /* start non-signaled */
381 NULL ); /* unnamed */
382 return !p_condvar->event;
384 #elif defined( WIN32 )
385 /* Initialize counter */
386 p_condvar->i_waiting_threads = 0;
389 p_condvar->i_win9x_cv = p_this->p_libvlc_global->i_win9x_cv;
390 p_condvar->SignalObjectAndWait = p_this->p_libvlc_global->SignalObjectAndWait;
392 if( (p_condvar->SignalObjectAndWait &&
393 !p_this->p_libvlc_global->b_fast_mutex)
394 || p_condvar->i_win9x_cv == 0 )
396 /* Create an auto-reset event. */
397 p_condvar->event = CreateEvent( NULL, /* no security */
398 FALSE, /* auto-reset event */
399 FALSE, /* start non-signaled */
400 NULL ); /* unnamed */
402 p_condvar->semaphore = NULL;
403 return !p_condvar->event;
407 p_condvar->semaphore = CreateSemaphore( NULL, /* no security */
408 0, /* initial count */
409 0x7fffffff, /* max count */
410 NULL ); /* unnamed */
412 if( p_condvar->i_win9x_cv == 1 )
413 /* Create a manual-reset event initially signaled. */
414 p_condvar->event = CreateEvent( NULL, TRUE, TRUE, NULL );
416 /* Create a auto-reset event. */
417 p_condvar->event = CreateEvent( NULL, FALSE, FALSE, NULL );
419 InitializeCriticalSection( &p_condvar->csection );
421 return !p_condvar->semaphore || !p_condvar->event;
424 #elif defined( HAVE_KERNEL_SCHEDULER_H )
430 if( p_condvar->init == 9999 )
435 p_condvar->thread = -1;
436 p_condvar->init = 9999;
439 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
440 return pthread_cond_init( &p_condvar->cond, NULL );
442 #elif defined( HAVE_CTHREADS_H )
443 /* condition_init() */
444 spin_lock_init( &p_condvar->lock );
445 cthread_queue_init( &p_condvar->queue );
447 p_condvar->implications = 0;
454 /*****************************************************************************
455 * vlc_cond_destroy: destroy a condition, inner version
456 *****************************************************************************/
457 int __vlc_cond_destroy( const char * psz_file, int i_line, vlc_cond_t *p_condvar )
460 /* In case of error : */
462 const char * psz_error = "";
464 #if defined( PTH_INIT_IN_PTH_H )
467 #elif defined( ST_INIT_IN_ST_H )
468 i_result = st_cond_destroy( p_condvar->cond );
470 #elif defined( UNDER_CE )
471 i_result = !CloseHandle( p_condvar->event );
473 #elif defined( WIN32 )
474 if( !p_condvar->semaphore )
475 i_result = !CloseHandle( p_condvar->event );
477 i_result = !CloseHandle( p_condvar->event )
478 || !CloseHandle( p_condvar->semaphore );
480 if( p_condvar->semaphore != NULL )
481 DeleteCriticalSection( &p_condvar->csection );
483 #elif defined( HAVE_KERNEL_SCHEDULER_H )
487 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
488 i_result = pthread_cond_destroy( &p_condvar->cond );
491 i_thread = CAST_PTHREAD_TO_INT(pthread_self());
492 psz_error = strerror(i_result);
495 #elif defined( HAVE_CTHREADS_H )
502 msg_Err( p_condvar->p_this,
503 "thread %d: cond_destroy failed at %s:%d (%d:%s)",
504 i_thread, psz_file, i_line, i_result, psz_error );
509 /*****************************************************************************
510 * vlc_tls_create: create a thread-local variable
511 *****************************************************************************/
512 int __vlc_threadvar_create( vlc_object_t *p_this, vlc_threadvar_t *p_tls )
516 #if defined( PTH_INIT_IN_PTH_H )
517 i_ret = pth_key_create( &p_tls->handle, NULL );
518 #elif defined( HAVE_KERNEL_SCHEDULER_H )
519 msg_Err( p_this, "TLS not implemented" );
521 #elif defined( ST_INIT_IN_ST_H )
522 i_ret = st_key_create( &p_tls->handle, NULL );
523 #elif defined( UNDER_CE ) || defined( WIN32 )
524 #elif defined( WIN32 )
525 p_tls->handle = TlsAlloc();
526 i_ret = !( p_tls->handle == 0xFFFFFFFF );
528 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
529 i_ret = pthread_key_create( &p_tls->handle, NULL );
530 #elif defined( HAVE_CTHREADS_H )
531 i_ret = cthread_keycreate( &p_tls-handle );
536 /*****************************************************************************
537 * vlc_thread_create: create a thread, inner version
538 *****************************************************************************
539 * Note that i_priority is only taken into account on platforms supporting
540 * userland real-time priority threads.
541 *****************************************************************************/
542 int __vlc_thread_create( vlc_object_t *p_this, const char * psz_file, int i_line,
543 const char *psz_name, void * ( *func ) ( void * ),
544 int i_priority, vlc_bool_t b_wait )
547 void *p_data = (void *)p_this;
549 vlc_mutex_lock( &p_this->object_lock );
551 #if defined( PTH_INIT_IN_PTH_H )
552 p_this->thread_id = pth_spawn( PTH_ATTR_DEFAULT, func, p_data );
553 i_ret = p_this->thread_id == NULL;
555 #elif defined( ST_INIT_IN_ST_H )
556 p_this->thread_id = st_thread_create( func, p_data, 1, 0 );
559 #elif defined( WIN32 ) || defined( UNDER_CE )
562 /* When using the MSVCRT C library you have to use the _beginthreadex
563 * function instead of CreateThread, otherwise you'll end up with
564 * memory leaks and the signal functions not working (see Microsoft
565 * Knowledge Base, article 104641) */
567 #if defined( UNDER_CE )
568 (HANDLE)CreateThread( NULL, 0, (PTHREAD_START) func,
569 p_data, 0, &threadID );
571 (HANDLE)_beginthreadex( NULL, 0, (PTHREAD_START) func,
572 p_data, 0, &threadID );
576 if( p_this->thread_id && i_priority )
578 if( !SetThreadPriority(p_this->thread_id, i_priority) )
580 msg_Warn( p_this, "couldn't set a faster priority" );
585 i_ret = ( p_this->thread_id ? 0 : 1 );
587 #elif defined( HAVE_KERNEL_SCHEDULER_H )
588 p_this->thread_id = spawn_thread( (thread_func)func, psz_name,
589 i_priority, p_data );
590 i_ret = resume_thread( p_this->thread_id );
592 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
593 i_ret = pthread_create( &p_this->thread_id, NULL, func, p_data );
596 if( config_GetInt( p_this, "rt-priority" ) )
599 int i_error, i_policy;
600 struct sched_param param;
602 memset( ¶m, 0, sizeof(struct sched_param) );
603 if( config_GetType( p_this, "rt-offset" ) )
605 i_priority += config_GetInt( p_this, "rt-offset" );
607 if( i_priority <= 0 )
609 param.sched_priority = (-1) * i_priority;
610 i_policy = SCHED_OTHER;
614 param.sched_priority = i_priority;
617 if( (i_error = pthread_setschedparam( p_this->thread_id,
618 i_policy, ¶m )) )
620 msg_Warn( p_this, "couldn't set thread priority (%s:%d): %s",
621 psz_file, i_line, strerror(i_error) );
632 #elif defined( HAVE_CTHREADS_H )
633 p_this->thread_id = cthread_fork( (cthread_fn_t)func, (any_t)p_data );
642 msg_Dbg( p_this, "waiting for thread completion" );
643 vlc_cond_wait( &p_this->object_wait, &p_this->object_lock );
646 p_this->b_thread = 1;
648 msg_Dbg( p_this, "thread %u (%s) created at priority %d (%s:%d)",
649 (unsigned int)p_this->thread_id, psz_name, i_priority,
652 vlc_mutex_unlock( &p_this->object_lock );
656 msg_Err( p_this, "%s thread could not be created at %s:%d (%s)",
657 psz_name, psz_file, i_line, strerror(i_ret) );
658 vlc_mutex_unlock( &p_this->object_lock );
664 /*****************************************************************************
665 * vlc_thread_set_priority: set the priority of the current thread when we
666 * couldn't set it in vlc_thread_create (for instance for the main thread)
667 *****************************************************************************/
668 int __vlc_thread_set_priority( vlc_object_t *p_this, const char * psz_file,
669 int i_line, int i_priority )
671 #if defined( PTH_INIT_IN_PTH_H ) || defined( ST_INIT_IN_ST_H )
672 #elif defined( WIN32 ) || defined( UNDER_CE )
673 if( !SetThreadPriority(GetCurrentThread(), i_priority) )
675 msg_Warn( p_this, "couldn't set a faster priority" );
679 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
681 if( config_GetInt( p_this, "rt-priority" ) )
684 int i_error, i_policy;
685 struct sched_param param;
687 memset( ¶m, 0, sizeof(struct sched_param) );
688 if( config_GetType( p_this, "rt-offset" ) )
690 i_priority += config_GetInt( p_this, "rt-offset" );
692 if( i_priority <= 0 )
694 param.sched_priority = (-1) * i_priority;
695 i_policy = SCHED_OTHER;
699 param.sched_priority = i_priority;
702 if( !p_this->thread_id )
703 p_this->thread_id = pthread_self();
704 if( (i_error = pthread_setschedparam( p_this->thread_id,
705 i_policy, ¶m )) )
707 msg_Warn( p_this, "couldn't set thread priority (%s:%d): %s",
708 psz_file, i_line, strerror(i_error) );
717 /*****************************************************************************
718 * vlc_thread_ready: tell the parent thread we were successfully spawned
719 *****************************************************************************/
720 void __vlc_thread_ready( vlc_object_t *p_this )
722 vlc_mutex_lock( &p_this->object_lock );
723 vlc_cond_signal( &p_this->object_wait );
724 vlc_mutex_unlock( &p_this->object_lock );
727 /*****************************************************************************
728 * vlc_thread_join: wait until a thread exits, inner version
729 *****************************************************************************/
730 void __vlc_thread_join( vlc_object_t *p_this, const char * psz_file, int i_line )
734 #if defined( PTH_INIT_IN_PTH_H )
735 i_ret = ( pth_join( p_this->thread_id, NULL ) == FALSE );
737 #elif defined( ST_INIT_IN_ST_H )
738 i_ret = st_thread_join( p_this->thread_id, NULL );
740 #elif defined( UNDER_CE ) || defined( WIN32 )
742 BOOL (WINAPI *OurGetThreadTimes)( HANDLE, FILETIME*, FILETIME*,
743 FILETIME*, FILETIME* );
744 FILETIME create_ft, exit_ft, kernel_ft, user_ft;
745 int64_t real_time, kernel_time, user_time;
747 WaitForSingleObject( p_this->thread_id, INFINITE );
749 #if defined( UNDER_CE )
750 hmodule = GetModuleHandle( _T("COREDLL") );
752 hmodule = GetModuleHandle( _T("KERNEL32") );
754 OurGetThreadTimes = (BOOL (WINAPI*)( HANDLE, FILETIME*, FILETIME*,
755 FILETIME*, FILETIME* ))
756 GetProcAddress( hmodule, _T("GetThreadTimes") );
758 if( OurGetThreadTimes &&
759 OurGetThreadTimes( p_this->thread_id,
760 &create_ft, &exit_ft, &kernel_ft, &user_ft ) )
763 ((((int64_t)exit_ft.dwHighDateTime)<<32)| exit_ft.dwLowDateTime) -
764 ((((int64_t)create_ft.dwHighDateTime)<<32)| create_ft.dwLowDateTime);
768 ((((int64_t)kernel_ft.dwHighDateTime)<<32)|
769 kernel_ft.dwLowDateTime) / 10;
772 ((((int64_t)user_ft.dwHighDateTime)<<32)|
773 user_ft.dwLowDateTime) / 10;
775 msg_Dbg( p_this, "thread times: "
776 "real "I64Fd"m%fs, kernel "I64Fd"m%fs, user "I64Fd"m%fs",
777 real_time/60/1000000,
778 (double)((real_time%(60*1000000))/1000000.0),
779 kernel_time/60/1000000,
780 (double)((kernel_time%(60*1000000))/1000000.0),
781 user_time/60/1000000,
782 (double)((user_time%(60*1000000))/1000000.0) );
784 CloseHandle( p_this->thread_id );
786 #elif defined( HAVE_KERNEL_SCHEDULER_H )
788 wait_for_thread( p_this->thread_id, &exit_value );
790 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
791 i_ret = pthread_join( p_this->thread_id, NULL );
793 #elif defined( HAVE_CTHREADS_H )
794 cthread_join( p_this->thread_id );
801 msg_Err( p_this, "thread_join(%u) failed at %s:%d (%s)",
802 (unsigned int)p_this->thread_id, psz_file, i_line,
807 msg_Dbg( p_this, "thread %u joined (%s:%d)",
808 (unsigned int)p_this->thread_id, psz_file, i_line );
811 p_this->b_thread = 0;