Commit 8ed38573 authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

misc/threads.c: Implement vlc_threads_error(), that is called when an error is...

misc/threads.c: Implement vlc_threads_error(), that is called when an error is encountered in the threading system. The whole point of this is to ease debugging of such situation, by exposing a nice symbol on which we can break. (This costs nearly nothing).
parent d53cfd89
......@@ -35,6 +35,7 @@
/*****************************************************************************
* Function definitions
*****************************************************************************/
VLC_EXPORT( void, __vlc_threads_error, ( vlc_object_t *) );
VLC_EXPORT( int, __vlc_mutex_init, ( vlc_object_t *, vlc_mutex_t * ) );
VLC_EXPORT( int, __vlc_mutex_destroy, ( const char *, int, vlc_mutex_t * ) );
VLC_EXPORT( int, __vlc_cond_init, ( vlc_object_t *, vlc_cond_t * ) );
......@@ -45,6 +46,12 @@ VLC_EXPORT( int, __vlc_thread_set_priority, ( vlc_object_t *, const char *, int
VLC_EXPORT( void, __vlc_thread_ready, ( vlc_object_t * ) );
VLC_EXPORT( void, __vlc_thread_join, ( vlc_object_t *, const char *, int ) );
/*****************************************************************************
* vlc_threads_error: Signalize an error in the threading system
*****************************************************************************/
#define vlc_threads_error( P_THIS ) \
__vlc_threads_error( VLC_OBJECT(P_THIS) )
/*****************************************************************************
* vlc_threads_init: initialize threads system
*****************************************************************************/
......@@ -139,6 +146,7 @@ static inline int __vlc_mutex_lock( const char * psz_file, int i_line,
msg_Err( p_mutex->p_this,
"thread %li: mutex_lock failed at %s:%d (%d:%m)",
i_thread, psz_file, i_line, i_result );
vlc_threads_error( p_mutex->p_this );
}
return i_result;
}
......@@ -215,6 +223,7 @@ static inline int __vlc_mutex_unlock( const char * psz_file, int i_line,
msg_Err( p_mutex->p_this,
"thread %li: mutex_unlock failed at %s:%d (%d:%m)",
i_thread, psz_file, i_line, i_result );
vlc_threads_error( p_mutex->p_this );
}
return i_result;
......@@ -361,6 +370,7 @@ static inline int __vlc_cond_signal( const char * psz_file, int i_line,
msg_Err( p_condvar->p_this,
"thread %li: cond_signal failed at %s:%d (%d:%m)",
i_thread, psz_file, i_line, i_result );
vlc_threads_error( p_condvar->p_this );
}
return i_result;
......@@ -544,6 +554,7 @@ static inline int __vlc_cond_wait( const char * psz_file, int i_line,
msg_Err( p_condvar->p_this,
"thread %li: cond_wait failed at %s:%d (%d:%m)",
i_thread, psz_file, i_line, i_result );
vlc_threads_error( p_condvar->p_this );
}
return i_result;
......@@ -702,6 +713,7 @@ static inline int __vlc_cond_timedwait( const char * psz_file, int i_line,
msg_Err( p_condvar->p_this,
"thread %li: cond_wait failed at %s:%d (%d:%m)",
i_thread, psz_file, i_line, i_res );
vlc_threads_error( p_condvar->p_this );
}
return i_res;
......
......@@ -77,6 +77,19 @@ static pthread_mutex_t once_mutex = PTHREAD_MUTEX_INITIALIZER;
vlc_threadvar_t msg_context_global_key;
/*****************************************************************************
* vlc_threads_error: Report an error from the threading mecanism
*****************************************************************************
* This is especially useful to debug those errors, as this is a nice symbol
* on which you can break.
*****************************************************************************/
void
__vlc_threads_error( vlc_object_t *p_this )
{
msg_Err( p_this, "Error detected. Put a breakpoint in '%s' to debug.",
__func__ );
}
/*****************************************************************************
* vlc_threads_init: initialize threads system
*****************************************************************************
......@@ -379,6 +392,7 @@ int __vlc_mutex_destroy( const char * psz_file, int i_line, vlc_mutex_t *p_mutex
msg_Err( p_mutex->p_this,
"thread %d: mutex_destroy failed at %s:%d (%d:%m)",
i_thread, psz_file, i_line, i_result );
vlc_threads_error( p_mutex->p_this );
}
return i_result;
}
......@@ -541,6 +555,7 @@ int __vlc_cond_destroy( const char * psz_file, int i_line, vlc_cond_t *p_condvar
msg_Err( p_condvar->p_this,
"thread %d: cond_destroy failed at %s:%d (%d:%m)",
i_thread, psz_file, i_line, i_result );
vlc_threads_error( p_condvar->p_this );
}
return i_result;
}
......@@ -710,6 +725,7 @@ int __vlc_thread_create( vlc_object_t *p_this, const char * psz_file, int i_line
errno = i_ret;
msg_Err( p_this, "%s thread could not be created at %s:%d (%m)",
psz_name, psz_file, i_line );
vlc_threads_error( p_this );
vlc_mutex_unlock( &p_this->object_lock );
}
......@@ -811,6 +827,7 @@ void __vlc_thread_join( vlc_object_t *p_this, const char * psz_file, int i_line
msg_Err( p_this, "thread_join(%u) failed at %s:%d (%s)",
(unsigned int)p_priv->thread_id.id,
psz_file, i_line, GetLastError() );
vlc_threads_error( p_this );
p_priv->b_thread = VLC_FALSE;
return;
}
......@@ -885,6 +902,7 @@ void __vlc_thread_join( vlc_object_t *p_this, const char * psz_file, int i_line
errno = i_ret;
msg_Err( p_this, "thread_join(%u) failed at %s:%d (%m)",
(unsigned int)p_priv->thread_id, psz_file, i_line );
vlc_threads_error( p_this );
}
else
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment