]> git.sesse.net Git - vlc/blobdiff - include/vlc_threads_funcs.h
Cosmetics, fix a few warnings, add a few memleaks (but we don't care do we?)
[vlc] / include / vlc_threads_funcs.h
index 078f5d5090c4a8aed4ca62ce062eb1edc65eae0a..b4822bce990a505f017adcaa6fd6f628135350ba 100644 (file)
   #error You are not libvlc or one of its plugins. You cannot include this file
 #endif
 
+#ifndef _VLC_THREADFUNCS_H_
+#define _VLC_THREADFUNCS_H_
+
 /*****************************************************************************
  * Function definitions
  *****************************************************************************/
-VLC_EXPORT( int,  __vlc_threads_init,  ( vlc_object_t * ) );
-VLC_EXPORT( int,  __vlc_threads_end,   ( 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 * ) );
@@ -119,6 +120,9 @@ static inline int __vlc_mutex_lock( const char * psz_file, int i_line,
     }
 
 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
+#   define vlc_assert_locked( m ) \
+           assert (pthread_mutex_lock (&((m)->mutex)) == EDEADLK)
+
     i_result = pthread_mutex_lock( &p_mutex->mutex );
     if ( i_result )
     {
@@ -141,6 +145,10 @@ static inline int __vlc_mutex_lock( const char * psz_file, int i_line,
     return i_result;
 }
 
+#ifndef vlc_assert_locked
+# define vlc_assert_locked( m ) (void)0
+#endif
+
 /*****************************************************************************
  * vlc_mutex_unlock: unlock a mutex
  *****************************************************************************/
@@ -557,20 +565,19 @@ static inline int __vlc_cond_wait( const char * psz_file, int i_line,
 /*****************************************************************************
  * vlc_threadvar_set: create: set the value of a thread-local variable
  *****************************************************************************/
-#define vlc_threadvar_set( P_TLS , P_VAL )                                   \
-   __vlc_threadvar_set( __FILE__, __LINE__, P_TLS, P_VAL )
-
-static inline int __vlc_threadvar_set( char* psz_file, int line,
-                                        vlc_threadvar_t * p_tls, void *p_value )
+static inline int vlc_threadvar_set( vlc_threadvar_t * p_tls, void *p_value )
 {
     int i_ret;
 
-#if defined( PTH_INIT_IN_PTH_H ) || \
-    defined( ST_INIT_IN_ST_H ) || defined( HAVE_KERNEL_SCHEDULER_H )
+#if defined( PTH_INIT_IN_PTH_H )
+    return pth_key_setdata( p_tls->handle, p_value );
+#elif  defined( ST_INIT_IN_ST_H )
+    return st_thread_setspecific( p_tls->handle, p_value );
+#elif defined( HAVE_KERNEL_SCHEDULER_H )
     return -1;
 
 #elif defined( UNDER_CE ) || defined( WIN32 )
-    i_ret = ( TlsSetValue( &p_tls->handle, p_value ) != 0 );
+    i_ret = ( TlsSetValue( p_tls->handle, p_value ) != 0 );
 
 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
     i_ret = pthread_setspecific( p_tls->handle, p_value );
@@ -585,20 +592,18 @@ static inline int __vlc_threadvar_set( char* psz_file, int line,
 /*****************************************************************************
  * vlc_threadvar_get: create: get the value of a thread-local variable
  *****************************************************************************/
-#define vlc_threadvar_get( P_TLS )                                         \
-   __vlc_threadvar_get( __FILE__, __LINE__, P_TLS )
-
-static inline void* __vlc_threadvar_get( char* psz_file, int line,
-                                         vlc_threadvar_t * p_tls )
+static inline void* vlc_threadvar_get( vlc_threadvar_t * p_tls )
 {
     void* p_ret;
 
-#if defined( PTH_INIT_IN_PTH_H ) || \
-    defined( ST_INIT_IN_ST_H ) || defined( HAVE_KERNEL_SCHEDULER_H )
-    return NULL;
-
+#if defined( PTH_INIT_IN_PTH_H )
+    p_ret = pth_key_getdata( p_handle->key );
+#elif defined( ST_INIT_IN_ST_H )
+    p_ret = st_thread_getspecific( p_handle->key );
+#elif defined( HAVE_KERNEL_SCHEDULER_H )
+    p_ret = NULL;
 #elif defined( UNDER_CE ) || defined( WIN32 )
-    p_ret = TlsGetValue( &p_tls->handle );
+    p_ret = TlsGetValue( p_tls->handle );
 
 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
     p_ret = pthread_getspecific( p_tls->handle );
@@ -636,3 +641,5 @@ static inline void* __vlc_threadvar_get( char* psz_file, int line,
  *****************************************************************************/
 #define vlc_thread_join( P_THIS )                                           \
     __vlc_thread_join( VLC_OBJECT(P_THIS), __FILE__, __LINE__ )
+
+#endif