]> git.sesse.net Git - vlc/commitdiff
The TLS also needs to be cleaned up... should fix #1576
authorRémi Denis-Courmont <rem@videolan.org>
Sat, 10 May 2008 20:22:13 +0000 (23:22 +0300)
committerRémi Denis-Courmont <rem@videolan.org>
Sat, 10 May 2008 20:22:19 +0000 (23:22 +0300)
include/vlc_threads.h
src/libvlc.h
src/libvlc.sym
src/misc/messages.c
src/misc/threads.c

index ec07c4cbcd0808cacf1bc1ee74739b1e053cdec4..5f5c9980ff25ab1fdcd797be506b50cda70d788c 100644 (file)
@@ -170,7 +170,8 @@ VLC_EXPORT( int,  vlc_mutex_init_recursive, ( vlc_mutex_t * ) );
 VLC_EXPORT( void,  __vlc_mutex_destroy, ( const char *, int, vlc_mutex_t * ) );
 VLC_EXPORT( int,  __vlc_cond_init,     ( vlc_cond_t * ) );
 VLC_EXPORT( void,  __vlc_cond_destroy,  ( const char *, int, vlc_cond_t * ) );
-VLC_EXPORT( int, __vlc_threadvar_create, (vlc_threadvar_t * ) );
+VLC_EXPORT( int, vlc_threadvar_create, (vlc_threadvar_t * , void (*) (void *) ) );
+VLC_EXPORT( void, vlc_threadvar_delete, (vlc_threadvar_t *) );
 VLC_EXPORT( int,  __vlc_thread_create, ( vlc_object_t *, const char *, int, const char *, void * ( * ) ( void * ), int, bool ) );
 VLC_EXPORT( int,  __vlc_thread_set_priority, ( vlc_object_t *, const char *, int, int ) );
 VLC_EXPORT( void, __vlc_thread_ready,  ( vlc_object_t * ) );
@@ -433,12 +434,6 @@ static inline int __vlc_cond_timedwait( const char * psz_file, int i_line,
 #define vlc_cond_destroy( P_COND )                                          \
     __vlc_cond_destroy( __FILE__, __LINE__, P_COND )
 
-/*****************************************************************************
- * vlc_threadvar_create: create a thread-local variable
- *****************************************************************************/
-#define vlc_threadvar_create( PTHIS, P_TLS )                                 \
-   __vlc_threadvar_create( P_TLS )
-
 /*****************************************************************************
  * vlc_threadvar_set: create: set the value of a thread-local variable
  *****************************************************************************/
index c6ee5b35ece13a316ae2f239e20204728885e125..9b00320e981475eca34eb7f9310b98391070b4e5 100644 (file)
@@ -46,13 +46,6 @@ void system_End       ( libvlc_int_t * );
 int vlc_threads_init( void );
 void vlc_threads_end( void );
 
-/** The global thread var for msg stack context
- *  We store this as a static global variable so we don't need a vlc_object_t
- *  everywhere.
- *  This key is created in vlc_threads_init and is therefore ready to use at
- *  the very beginning of the universe */
-extern vlc_threadvar_t msg_context_global_key;
-
 /*
  * CPU capabilities
  */
@@ -107,6 +100,13 @@ typedef struct
 void msg_StackSet ( int, const char*, ... );
 void msg_StackAdd ( const char*, ... );
 const char* msg_StackMsg ( void );
+/** The global thread var for msg stack context
+ *  We store this as a static global variable so we don't need a vlc_object_t
+ *  everywhere.
+ *  This key is created in vlc_threads_init and is therefore ready to use at
+ *  the very beginning of the universe */
+extern vlc_threadvar_t msg_context_global_key;
+void msg_StackDestroy (void *);
 
 /*
  * Unicode stuff
index ac448a9c19588bc13007ea38f6452b9e86d01fa6..99be574e7712064b04219b3fac6b3e7b0bd6f021 100644 (file)
@@ -455,7 +455,8 @@ __vlc_thread_create
 __vlc_thread_join
 __vlc_thread_ready
 __vlc_thread_set_priority
-__vlc_threadvar_create
+vlc_threadvar_create
+vlc_threadvar_delete
 vlc_ureduce
 vlc_vasprintf
 VLC_Version
index 38752e90c073fe25d90aa20fa3961afbc0e45606..bfdd1d931d40d0a4dbd5a5757e9f25d3a1e88452 100644 (file)
@@ -614,6 +614,14 @@ static msg_context_t* GetContext(void)
     return p_ctx;
 }
 
+void msg_StackDestroy (void *data)
+{
+    msg_context_t *p_ctx = data;
+
+    free (p_ctx->psz_message);
+    free (p_ctx);
+}
+
 void msg_StackSet( int i_code, const char *psz_message, ... )
 {
     va_list ap;
@@ -621,10 +629,9 @@ void msg_StackSet( int i_code, const char *psz_message, ... )
 
     if( p_ctx == NULL )
         return;
-
-    va_start( ap, psz_message );
     free( p_ctx->psz_message );
 
+    va_start( ap, psz_message );
     if( vasprintf( &p_ctx->psz_message, psz_message, ap ) == -1 )
         p_ctx->psz_message = NULL;
     va_end( ap );
index 867ca3e7e04aefbb116a3d110d80ba1dc839122d..e8ae01324b64a4b1bd1aa714d987a306b8e1bfe1 100644 (file)
@@ -145,7 +145,7 @@ int vlc_threads_init( void )
         }
 
         /* We should be safe now. Do all the initialization stuff we want. */
-        vlc_threadvar_create( p_root, &msg_context_global_key );
+        vlc_threadvar_create( &msg_context_global_key, msg_StackDestroy );
     }
     i_initializations++;
 
@@ -173,7 +173,10 @@ void vlc_threads_end( void )
     assert( i_initializations > 0 );
 
     if( i_initializations == 1 )
+    {
         vlc_object_release( p_root );
+        vlc_threadvar_delete( &msg_context_global_key );
+    }
     i_initializations--;
 
 #if defined( LIBVLC_USE_PTHREAD )
@@ -374,13 +377,14 @@ void __vlc_cond_destroy( const char * psz_file, int i_line, vlc_cond_t *p_condva
 /*****************************************************************************
  * vlc_tls_create: create a thread-local variable
  *****************************************************************************/
-int __vlc_threadvar_create( vlc_threadvar_t *p_tls )
+int vlc_threadvar_create( vlc_threadvar_t *p_tls, void (*destr) (void *) )
 {
-    int i_ret = -1;
+    int i_ret;
 
 #if defined( LIBVLC_USE_PTHREAD )
-    i_ret =  pthread_key_create( p_tls, NULL );
+    i_ret =  pthread_key_create( p_tls, destr );
 #elif defined( UNDER_CE )
+    i_ret = ENOSYS;
 #elif defined( WIN32 )
     *p_tls = TlsAlloc();
     i_ret = (*p_tls == TLS_OUT_OF_INDEXES) ? EAGAIN : 0;
@@ -390,6 +394,18 @@ int __vlc_threadvar_create( vlc_threadvar_t *p_tls )
     return i_ret;
 }
 
+void vlc_threadvar_delete (vlc_threadvar_t *p_tls)
+{
+#if defined( LIBVLC_USE_PTHREAD )
+    pthread_key_delete (p_tls);
+#elif defined( UNDER_CE )
+#elif defined( WIN32 )
+    TlsFree (*p_tls);
+#else
+# error Unimplemented!
+#endif
+}
+
 /*****************************************************************************
  * vlc_thread_create: create a thread, inner version
  *****************************************************************************