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 b_fast_mutex = config_GetInt( p_this, "fast-mutex" );
78 i_win9x_cv = config_GetInt( p_this, "win9x-cv-method" );
79 #elif defined( HAVE_KERNEL_SCHEDULER_H )
80 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
81 pthread_mutex_lock( &once_mutex );
82 #elif defined( HAVE_CTHREADS_H )
85 if( i_status == VLC_THREADS_UNINITIALIZED )
87 i_status = VLC_THREADS_PENDING;
89 /* We should be safe now. Do all the initialization stuff we want. */
90 p_libvlc_global->b_ready = VLC_FALSE;
92 #if defined( PTH_INIT_IN_PTH_H )
93 i_ret = ( pth_init() == FALSE );
95 #elif defined( ST_INIT_IN_ST_H )
98 #elif defined( UNDER_CE )
99 /* Nothing to initialize */
101 #elif defined( WIN32 )
102 /* Dynamically get the address of SignalObjectAndWait */
103 if( GetVersion() < 0x80000000 )
107 /* We are running on NT/2K/XP, we can use SignalObjectAndWait */
108 hInstLib = LoadLibrary( "kernel32" );
111 pf_SignalObjectAndWait =
112 (SIGNALOBJECTANDWAIT)GetProcAddress( hInstLib,
113 "SignalObjectAndWait" );
117 #elif defined( HAVE_KERNEL_SCHEDULER_H )
118 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
119 #elif defined( HAVE_CTHREADS_H )
122 p_root = vlc_object_create( p_libvlc_global, VLC_OBJECT_GLOBAL );
128 i_status = VLC_THREADS_ERROR;
133 i_status = VLC_THREADS_READY;
136 vlc_threadvar_create( p_root, &msg_context_global_key );
140 /* Just increment the initialization count */
144 /* If we have lazy mutex initialization support, unlock the mutex;
145 * otherwize, do a naive wait loop. */
146 #if defined( PTH_INIT_IN_PTH_H )
147 while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
148 #elif defined( ST_INIT_IN_ST_H )
149 while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
150 #elif defined( UNDER_CE )
151 while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
152 #elif defined( WIN32 )
153 while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
154 #elif defined( HAVE_KERNEL_SCHEDULER_H )
155 while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
156 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
157 pthread_mutex_unlock( &once_mutex );
158 #elif defined( HAVE_CTHREADS_H )
159 while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
162 if( i_status != VLC_THREADS_READY )
170 /*****************************************************************************
171 * vlc_threads_end: stop threads system
172 *****************************************************************************
173 * FIXME: This function is far from being threadsafe.
174 *****************************************************************************/
175 int __vlc_threads_end( vlc_object_t *p_this )
178 #if defined( PTH_INIT_IN_PTH_H )
179 #elif defined( ST_INIT_IN_ST_H )
180 #elif defined( UNDER_CE )
181 #elif defined( WIN32 )
182 #elif defined( HAVE_KERNEL_SCHEDULER_H )
183 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
184 pthread_mutex_lock( &once_mutex );
185 #elif defined( HAVE_CTHREADS_H )
188 if( i_initializations == 0 )
192 if( i_initializations == 0 )
194 i_status = VLC_THREADS_UNINITIALIZED;
195 vlc_object_destroy( p_root );
198 #if defined( PTH_INIT_IN_PTH_H )
199 if( i_initializations == 0 )
201 return ( pth_kill() == FALSE );
204 #elif defined( ST_INIT_IN_ST_H )
205 #elif defined( UNDER_CE )
206 #elif defined( WIN32 )
207 #elif defined( HAVE_KERNEL_SCHEDULER_H )
208 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
209 pthread_mutex_unlock( &once_mutex );
210 #elif defined( HAVE_CTHREADS_H )
215 /*****************************************************************************
216 * vlc_mutex_init: initialize a mutex
217 *****************************************************************************/
218 int __vlc_mutex_init( vlc_object_t *p_this, vlc_mutex_t *p_mutex )
220 p_mutex->p_this = p_this;
222 #if defined( PTH_INIT_IN_PTH_H )
223 return ( pth_mutex_init( &p_mutex->mutex ) == FALSE );
225 #elif defined( ST_INIT_IN_ST_H )
226 p_mutex->mutex = st_mutex_new();
227 return ( p_mutex->mutex == NULL ) ? errno : 0;
229 #elif defined( UNDER_CE )
230 InitializeCriticalSection( &p_mutex->csection );
233 #elif defined( WIN32 )
234 /* We use mutexes on WinNT/2K/XP because we can use the SignalObjectAndWait
235 * function and have a 100% correct vlc_cond_wait() implementation.
236 * As this function is not available on Win9x, we can use the faster
237 * CriticalSections */
238 if( pf_SignalObjectAndWait && !b_fast_mutex )
240 /* We are running on NT/2K/XP, we can use SignalObjectAndWait */
241 p_mutex->mutex = CreateMutex( 0, FALSE, 0 );
242 return ( p_mutex->mutex != NULL ? 0 : 1 );
246 p_mutex->mutex = NULL;
247 InitializeCriticalSection( &p_mutex->csection );
251 #elif defined( HAVE_KERNEL_SCHEDULER_H )
252 /* check the arguments and whether it's already been initialized */
253 if( p_mutex == NULL )
258 if( p_mutex->init == 9999 )
263 p_mutex->lock = create_sem( 1, "BeMutex" );
264 if( p_mutex->lock < B_NO_ERROR )
269 p_mutex->init = 9999;
272 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
273 # if defined(DEBUG) && defined(SYS_LINUX)
275 /* Create error-checking mutex to detect problems more easily. */
276 pthread_mutexattr_t attr;
279 pthread_mutexattr_init( &attr );
280 pthread_mutexattr_setkind_np( &attr, PTHREAD_MUTEX_ERRORCHECK_NP );
281 i_result = pthread_mutex_init( &p_mutex->mutex, &attr );
282 pthread_mutexattr_destroy( &attr );
286 return pthread_mutex_init( &p_mutex->mutex, NULL );
288 #elif defined( HAVE_CTHREADS_H )
289 mutex_init( p_mutex );
295 /*****************************************************************************
296 * vlc_mutex_destroy: destroy a mutex, inner version
297 *****************************************************************************/
298 int __vlc_mutex_destroy( const char * psz_file, int i_line, vlc_mutex_t *p_mutex )
301 /* In case of error : */
303 const char * psz_error = "";
305 #if defined( PTH_INIT_IN_PTH_H )
308 #elif defined( ST_INIT_IN_ST_H )
309 i_result = st_mutex_destroy( p_mutex->mutex );
311 #elif defined( UNDER_CE )
312 DeleteCriticalSection( &p_mutex->csection );
315 #elif defined( WIN32 )
318 CloseHandle( p_mutex->mutex );
322 DeleteCriticalSection( &p_mutex->csection );
326 #elif defined( HAVE_KERNEL_SCHEDULER_H )
327 if( p_mutex->init == 9999 )
329 delete_sem( p_mutex->lock );
335 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
336 i_result = pthread_mutex_destroy( &p_mutex->mutex );
339 i_thread = CAST_PTHREAD_TO_INT(pthread_self());
340 psz_error = strerror(i_result);
343 #elif defined( HAVE_CTHREADS_H )
350 msg_Err( p_mutex->p_this,
351 "thread %d: mutex_destroy failed at %s:%d (%d:%s)",
352 i_thread, psz_file, i_line, i_result, psz_error );
357 /*****************************************************************************
358 * vlc_cond_init: initialize a condition
359 *****************************************************************************/
360 int __vlc_cond_init( vlc_object_t *p_this, vlc_cond_t *p_condvar )
362 p_condvar->p_this = p_this;
364 #if defined( PTH_INIT_IN_PTH_H )
365 return ( pth_cond_init( &p_condvar->cond ) == FALSE );
367 #elif defined( ST_INIT_IN_ST_H )
368 p_condvar->cond = st_cond_new();
369 return ( p_condvar->cond == NULL ) ? errno : 0;
371 #elif defined( UNDER_CE )
372 /* Initialize counter */
373 p_condvar->i_waiting_threads = 0;
375 /* Create an auto-reset event. */
376 p_condvar->event = CreateEvent( NULL, /* no security */
377 FALSE, /* auto-reset event */
378 FALSE, /* start non-signaled */
379 NULL ); /* unnamed */
380 return !p_condvar->event;
382 #elif defined( WIN32 )
383 /* Initialize counter */
384 p_condvar->i_waiting_threads = 0;
387 p_condvar->i_win9x_cv = i_win9x_cv;
388 p_condvar->SignalObjectAndWait = pf_SignalObjectAndWait;
390 if( (p_condvar->SignalObjectAndWait && !b_fast_mutex)
391 || p_condvar->i_win9x_cv == 0 )
393 /* Create an auto-reset event. */
394 p_condvar->event = CreateEvent( NULL, /* no security */
395 FALSE, /* auto-reset event */
396 FALSE, /* start non-signaled */
397 NULL ); /* unnamed */
399 p_condvar->semaphore = NULL;
400 return !p_condvar->event;
404 p_condvar->semaphore = CreateSemaphore( NULL, /* no security */
405 0, /* initial count */
406 0x7fffffff, /* max count */
407 NULL ); /* unnamed */
409 if( p_condvar->i_win9x_cv == 1 )
410 /* Create a manual-reset event initially signaled. */
411 p_condvar->event = CreateEvent( NULL, TRUE, TRUE, NULL );
413 /* Create a auto-reset event. */
414 p_condvar->event = CreateEvent( NULL, FALSE, FALSE, NULL );
416 InitializeCriticalSection( &p_condvar->csection );
418 return !p_condvar->semaphore || !p_condvar->event;
421 #elif defined( HAVE_KERNEL_SCHEDULER_H )
427 if( p_condvar->init == 9999 )
432 p_condvar->thread = -1;
433 p_condvar->init = 9999;
436 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
437 return pthread_cond_init( &p_condvar->cond, NULL );
439 #elif defined( HAVE_CTHREADS_H )
440 /* condition_init() */
441 spin_lock_init( &p_condvar->lock );
442 cthread_queue_init( &p_condvar->queue );
444 p_condvar->implications = 0;
451 /*****************************************************************************
452 * vlc_cond_destroy: destroy a condition, inner version
453 *****************************************************************************/
454 int __vlc_cond_destroy( const char * psz_file, int i_line, vlc_cond_t *p_condvar )
457 /* In case of error : */
459 const char * psz_error = "";
461 #if defined( PTH_INIT_IN_PTH_H )
464 #elif defined( ST_INIT_IN_ST_H )
465 i_result = st_cond_destroy( p_condvar->cond );
467 #elif defined( UNDER_CE )
468 i_result = !CloseHandle( p_condvar->event );
470 #elif defined( WIN32 )
471 if( !p_condvar->semaphore )
472 i_result = !CloseHandle( p_condvar->event );
474 i_result = !CloseHandle( p_condvar->event )
475 || !CloseHandle( p_condvar->semaphore );
477 if( p_condvar->semaphore != NULL )
478 DeleteCriticalSection( &p_condvar->csection );
480 #elif defined( HAVE_KERNEL_SCHEDULER_H )
484 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
485 i_result = pthread_cond_destroy( &p_condvar->cond );
488 i_thread = CAST_PTHREAD_TO_INT(pthread_self());
489 psz_error = strerror(i_result);
492 #elif defined( HAVE_CTHREADS_H )
499 msg_Err( p_condvar->p_this,
500 "thread %d: cond_destroy failed at %s:%d (%d:%s)",
501 i_thread, psz_file, i_line, i_result, psz_error );
506 /*****************************************************************************
507 * vlc_tls_create: create a thread-local variable
508 *****************************************************************************/
509 int __vlc_threadvar_create( vlc_object_t *p_this, vlc_threadvar_t *p_tls )
513 #if defined( PTH_INIT_IN_PTH_H )
514 i_ret = pth_key_create( &p_tls->handle, NULL );
515 #elif defined( HAVE_KERNEL_SCHEDULER_H )
516 msg_Err( p_this, "TLS not implemented" );
518 #elif defined( ST_INIT_IN_ST_H )
519 i_ret = st_key_create( &p_tls->handle, NULL );
520 #elif defined( UNDER_CE ) || defined( WIN32 )
521 #elif defined( WIN32 )
522 p_tls->handle = TlsAlloc();
523 i_ret = !( p_tls->handle == 0xFFFFFFFF );
525 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
526 i_ret = pthread_key_create( &p_tls->handle, NULL );
527 #elif defined( HAVE_CTHREADS_H )
528 i_ret = cthread_keycreate( &p_tls-handle );
533 /*****************************************************************************
534 * vlc_thread_create: create a thread, inner version
535 *****************************************************************************
536 * Note that i_priority is only taken into account on platforms supporting
537 * userland real-time priority threads.
538 *****************************************************************************/
539 int __vlc_thread_create( vlc_object_t *p_this, const char * psz_file, int i_line,
540 const char *psz_name, void * ( *func ) ( void * ),
541 int i_priority, vlc_bool_t b_wait )
544 void *p_data = (void *)p_this;
546 vlc_mutex_lock( &p_this->object_lock );
548 #if defined( PTH_INIT_IN_PTH_H )
549 p_this->thread_id = pth_spawn( PTH_ATTR_DEFAULT, func, p_data );
550 i_ret = p_this->thread_id == NULL;
552 #elif defined( ST_INIT_IN_ST_H )
553 p_this->thread_id = st_thread_create( func, p_data, 1, 0 );
556 #elif defined( WIN32 ) || defined( UNDER_CE )
559 /* When using the MSVCRT C library you have to use the _beginthreadex
560 * function instead of CreateThread, otherwise you'll end up with
561 * memory leaks and the signal functions not working (see Microsoft
562 * Knowledge Base, article 104641) */
564 #if defined( UNDER_CE )
565 (HANDLE)CreateThread( NULL, 0, (PTHREAD_START) func,
566 p_data, 0, &threadID );
568 (HANDLE)_beginthreadex( NULL, 0, (PTHREAD_START) func,
569 p_data, 0, &threadID );
573 if( p_this->thread_id && i_priority )
575 if( !SetThreadPriority(p_this->thread_id, i_priority) )
577 msg_Warn( p_this, "couldn't set a faster priority" );
582 i_ret = ( p_this->thread_id ? 0 : 1 );
584 #elif defined( HAVE_KERNEL_SCHEDULER_H )
585 p_this->thread_id = spawn_thread( (thread_func)func, psz_name,
586 i_priority, p_data );
587 i_ret = resume_thread( p_this->thread_id );
589 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
590 i_ret = pthread_create( &p_this->thread_id, NULL, func, p_data );
593 if( config_GetInt( p_this, "rt-priority" ) )
596 int i_error, i_policy;
597 struct sched_param param;
599 memset( ¶m, 0, sizeof(struct sched_param) );
600 if( config_GetType( p_this, "rt-offset" ) )
602 i_priority += config_GetInt( p_this, "rt-offset" );
604 if( i_priority <= 0 )
606 param.sched_priority = (-1) * i_priority;
607 i_policy = SCHED_OTHER;
611 param.sched_priority = i_priority;
614 if( (i_error = pthread_setschedparam( p_this->thread_id,
615 i_policy, ¶m )) )
617 msg_Warn( p_this, "couldn't set thread priority (%s:%d): %s",
618 psz_file, i_line, strerror(i_error) );
629 #elif defined( HAVE_CTHREADS_H )
630 p_this->thread_id = cthread_fork( (cthread_fn_t)func, (any_t)p_data );
639 msg_Dbg( p_this, "waiting for thread completion" );
640 vlc_cond_wait( &p_this->object_wait, &p_this->object_lock );
643 p_this->b_thread = 1;
645 msg_Dbg( p_this, "thread %u (%s) created at priority %d (%s:%d)",
646 (unsigned int)p_this->thread_id, psz_name, i_priority,
649 vlc_mutex_unlock( &p_this->object_lock );
653 msg_Err( p_this, "%s thread could not be created at %s:%d (%s)",
654 psz_name, psz_file, i_line, strerror(i_ret) );
655 vlc_mutex_unlock( &p_this->object_lock );
661 /*****************************************************************************
662 * vlc_thread_set_priority: set the priority of the current thread when we
663 * couldn't set it in vlc_thread_create (for instance for the main thread)
664 *****************************************************************************/
665 int __vlc_thread_set_priority( vlc_object_t *p_this, const char * psz_file,
666 int i_line, int i_priority )
668 #if defined( PTH_INIT_IN_PTH_H ) || defined( ST_INIT_IN_ST_H )
669 #elif defined( WIN32 ) || defined( UNDER_CE )
670 if( !SetThreadPriority(GetCurrentThread(), i_priority) )
672 msg_Warn( p_this, "couldn't set a faster priority" );
676 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
678 if( config_GetInt( p_this, "rt-priority" ) )
681 int i_error, i_policy;
682 struct sched_param param;
684 memset( ¶m, 0, sizeof(struct sched_param) );
685 if( config_GetType( p_this, "rt-offset" ) )
687 i_priority += config_GetInt( p_this, "rt-offset" );
689 if( i_priority <= 0 )
691 param.sched_priority = (-1) * i_priority;
692 i_policy = SCHED_OTHER;
696 param.sched_priority = i_priority;
699 if( !p_this->thread_id )
700 p_this->thread_id = pthread_self();
701 if( (i_error = pthread_setschedparam( p_this->thread_id,
702 i_policy, ¶m )) )
704 msg_Warn( p_this, "couldn't set thread priority (%s:%d): %s",
705 psz_file, i_line, strerror(i_error) );
714 /*****************************************************************************
715 * vlc_thread_ready: tell the parent thread we were successfully spawned
716 *****************************************************************************/
717 void __vlc_thread_ready( vlc_object_t *p_this )
719 vlc_mutex_lock( &p_this->object_lock );
720 vlc_cond_signal( &p_this->object_wait );
721 vlc_mutex_unlock( &p_this->object_lock );
724 /*****************************************************************************
725 * vlc_thread_join: wait until a thread exits, inner version
726 *****************************************************************************/
727 void __vlc_thread_join( vlc_object_t *p_this, const char * psz_file, int i_line )
731 #if defined( PTH_INIT_IN_PTH_H )
732 i_ret = ( pth_join( p_this->thread_id, NULL ) == FALSE );
734 #elif defined( ST_INIT_IN_ST_H )
735 i_ret = st_thread_join( p_this->thread_id, NULL );
737 #elif defined( UNDER_CE ) || defined( WIN32 )
739 BOOL (WINAPI *OurGetThreadTimes)( HANDLE, FILETIME*, FILETIME*,
740 FILETIME*, FILETIME* );
741 FILETIME create_ft, exit_ft, kernel_ft, user_ft;
742 int64_t real_time, kernel_time, user_time;
744 WaitForSingleObject( p_this->thread_id, INFINITE );
746 #if defined( UNDER_CE )
747 hmodule = GetModuleHandle( _T("COREDLL") );
749 hmodule = GetModuleHandle( _T("KERNEL32") );
751 OurGetThreadTimes = (BOOL (WINAPI*)( HANDLE, FILETIME*, FILETIME*,
752 FILETIME*, FILETIME* ))
753 GetProcAddress( hmodule, _T("GetThreadTimes") );
755 if( OurGetThreadTimes &&
756 OurGetThreadTimes( p_this->thread_id,
757 &create_ft, &exit_ft, &kernel_ft, &user_ft ) )
760 ((((int64_t)exit_ft.dwHighDateTime)<<32)| exit_ft.dwLowDateTime) -
761 ((((int64_t)create_ft.dwHighDateTime)<<32)| create_ft.dwLowDateTime);
765 ((((int64_t)kernel_ft.dwHighDateTime)<<32)|
766 kernel_ft.dwLowDateTime) / 10;
769 ((((int64_t)user_ft.dwHighDateTime)<<32)|
770 user_ft.dwLowDateTime) / 10;
772 msg_Dbg( p_this, "thread times: "
773 "real "I64Fd"m%fs, kernel "I64Fd"m%fs, user "I64Fd"m%fs",
774 real_time/60/1000000,
775 (double)((real_time%(60*1000000))/1000000.0),
776 kernel_time/60/1000000,
777 (double)((kernel_time%(60*1000000))/1000000.0),
778 user_time/60/1000000,
779 (double)((user_time%(60*1000000))/1000000.0) );
781 CloseHandle( p_this->thread_id );
783 #elif defined( HAVE_KERNEL_SCHEDULER_H )
785 wait_for_thread( p_this->thread_id, &exit_value );
787 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
788 i_ret = pthread_join( p_this->thread_id, NULL );
790 #elif defined( HAVE_CTHREADS_H )
791 cthread_join( p_this->thread_id );
798 msg_Err( p_this, "thread_join(%u) failed at %s:%d (%s)",
799 (unsigned int)p_this->thread_id, psz_file, i_line,
804 msg_Dbg( p_this, "thread %u joined (%s:%d)",
805 (unsigned int)p_this->thread_id, psz_file, i_line );
808 p_this->b_thread = 0;