]> git.sesse.net Git - vlc/blobdiff - include/vlc_threads_funcs.h
Qt4 - fix some saving and reading size bugs. Patch by Andre Weber
[vlc] / include / vlc_threads_funcs.h
index 5d0c74ca5040fbcc2c08ce034285d56609b61106..2823aa8385214c3458ab2b312324ec6406b8535a 100644 (file)
@@ -35,7 +35,9 @@
 /*****************************************************************************
  * 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_init_recursive, ( 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 * ) );
 VLC_EXPORT( int,  __vlc_cond_destroy,  ( const char *, int, vlc_cond_t * ) );
@@ -45,6 +47,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
  *****************************************************************************/
@@ -63,16 +71,25 @@ VLC_EXPORT( void, __vlc_thread_join,   ( vlc_object_t *, const char *, int ) );
 #define vlc_mutex_init( P_THIS, P_MUTEX )                                   \
     __vlc_mutex_init( VLC_OBJECT(P_THIS), P_MUTEX )
 
+/*****************************************************************************
+ * vlc_mutex_init: initialize a recursive mutex (Don't use it)
+ *****************************************************************************/
+#define vlc_mutex_init_recursive( P_THIS, P_MUTEX )                         \
+    __vlc_mutex_init_recursive( VLC_OBJECT(P_THIS), P_MUTEX )
+
 /*****************************************************************************
  * vlc_mutex_lock: lock a mutex
  *****************************************************************************/
 #define vlc_mutex_lock( P_MUTEX )                                           \
     __vlc_mutex_lock( __FILE__, __LINE__, P_MUTEX )
 
-#ifdef __APPLE__
-#   define CAST_PTHREAD_TO_INT(t) (unsigned long int)(uintptr_t)(void *)t
-#else
-#   define CAST_PTHREAD_TO_INT(t) (unsigned long int)t
+#if defined( PTHREAD_COND_T_IN_PTHREAD_H )
+static inline unsigned long int CAST_PTHREAD_TO_INT (pthread_t th)
+{
+     union { pthread_t th; unsigned long int i; } v = { };
+     v.th = th;
+     return v.i;
+}
 #endif
 
 static inline int __vlc_mutex_lock( const char * psz_file, int i_line,
@@ -139,6 +156,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 +233,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 +380,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 +564,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 +723,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;