[vlc-devel] commit: The TLS also needs to be cleaned up... should fix #1576 ( Rémi Denis-Courmont )
git version control
git at videolan.org
Sat May 10 22:21:02 CEST 2008
vlc | branch: master | Rémi Denis-Courmont <rem at videolan.org> | Sat May 10 23:22:13 2008 +0300| [fb7f7d22b070fbe51775f102cc66bd84b04e44b4]
The TLS also needs to be cleaned up... should fix #1576
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=fb7f7d22b070fbe51775f102cc66bd84b04e44b4
---
include/vlc_threads.h | 9 ++-------
src/libvlc.h | 14 +++++++-------
src/libvlc.sym | 3 ++-
src/misc/messages.c | 11 +++++++++--
src/misc/threads.c | 24 ++++++++++++++++++++----
5 files changed, 40 insertions(+), 21 deletions(-)
diff --git a/include/vlc_threads.h b/include/vlc_threads.h
index ec07c4c..5f5c998 100644
--- a/include/vlc_threads.h
+++ b/include/vlc_threads.h
@@ -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 * ) );
@@ -434,12 +435,6 @@ static inline int __vlc_cond_timedwait( const char * psz_file, int i_line,
__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
*****************************************************************************/
static inline int vlc_threadvar_set( vlc_threadvar_t * p_tls, void *p_value )
diff --git a/src/libvlc.h b/src/libvlc.h
index c6ee5b3..9b00320 100644
--- a/src/libvlc.h
+++ b/src/libvlc.h
@@ -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
diff --git a/src/libvlc.sym b/src/libvlc.sym
index ac448a9..99be574 100644
--- a/src/libvlc.sym
+++ b/src/libvlc.sym
@@ -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
diff --git a/src/misc/messages.c b/src/misc/messages.c
index 38752e9..bfdd1d9 100644
--- a/src/misc/messages.c
+++ b/src/misc/messages.c
@@ -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 );
diff --git a/src/misc/threads.c b/src/misc/threads.c
index 867ca3e..e8ae013 100644
--- a/src/misc/threads.c
+++ b/src/misc/threads.c
@@ -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
*****************************************************************************
More information about the vlc-devel
mailing list