]> git.sesse.net Git - vlc/commitdiff
misc/threads.c: Implement vlc_threads_error(), that is called when an error is encoun...
authorPierre d'Herbemont <pdherbemont@videolan.org>
Wed, 12 Dec 2007 04:42:15 +0000 (04:42 +0000)
committerPierre d'Herbemont <pdherbemont@videolan.org>
Wed, 12 Dec 2007 04:42:15 +0000 (04:42 +0000)
include/vlc_threads_funcs.h
src/misc/threads.c

index 00ae68cf0c276b5b53ff81952838fe07fd4b2071..3be83a6566c82c8a574883a9a23b9b83aee4a495 100644 (file)
@@ -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;
index 647dd3773a87f6296509cb4f18b3059935da6b34..d8fdced017b184d18c9391b862d6db44186efa8c 100644 (file)
@@ -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
     {