Commit fb7f7d22 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

The TLS also needs to be cleaned up... should fix #1576

parent 7793bdcb
...@@ -170,7 +170,8 @@ VLC_EXPORT( int, vlc_mutex_init_recursive, ( vlc_mutex_t * ) ); ...@@ -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( void, __vlc_mutex_destroy, ( const char *, int, vlc_mutex_t * ) );
VLC_EXPORT( int, __vlc_cond_init, ( vlc_cond_t * ) ); VLC_EXPORT( int, __vlc_cond_init, ( vlc_cond_t * ) );
VLC_EXPORT( void, __vlc_cond_destroy, ( const char *, int, 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_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( int, __vlc_thread_set_priority, ( vlc_object_t *, const char *, int, int ) );
VLC_EXPORT( void, __vlc_thread_ready, ( vlc_object_t * ) ); 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, ...@@ -433,12 +434,6 @@ static inline int __vlc_cond_timedwait( const char * psz_file, int i_line,
#define vlc_cond_destroy( P_COND ) \ #define vlc_cond_destroy( P_COND ) \
__vlc_cond_destroy( __FILE__, __LINE__, 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 * vlc_threadvar_set: create: set the value of a thread-local variable
*****************************************************************************/ *****************************************************************************/
......
...@@ -46,13 +46,6 @@ void system_End ( libvlc_int_t * ); ...@@ -46,13 +46,6 @@ void system_End ( libvlc_int_t * );
int vlc_threads_init( void ); int vlc_threads_init( void );
void vlc_threads_end( 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 * CPU capabilities
*/ */
...@@ -107,6 +100,13 @@ typedef struct ...@@ -107,6 +100,13 @@ typedef struct
void msg_StackSet ( int, const char*, ... ); void msg_StackSet ( int, const char*, ... );
void msg_StackAdd ( const char*, ... ); void msg_StackAdd ( const char*, ... );
const char* msg_StackMsg ( void ); 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 * Unicode stuff
......
...@@ -455,7 +455,8 @@ __vlc_thread_create ...@@ -455,7 +455,8 @@ __vlc_thread_create
__vlc_thread_join __vlc_thread_join
__vlc_thread_ready __vlc_thread_ready
__vlc_thread_set_priority __vlc_thread_set_priority
__vlc_threadvar_create vlc_threadvar_create
vlc_threadvar_delete
vlc_ureduce vlc_ureduce
vlc_vasprintf vlc_vasprintf
VLC_Version VLC_Version
......
...@@ -614,6 +614,14 @@ static msg_context_t* GetContext(void) ...@@ -614,6 +614,14 @@ static msg_context_t* GetContext(void)
return p_ctx; 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, ... ) void msg_StackSet( int i_code, const char *psz_message, ... )
{ {
va_list ap; va_list ap;
...@@ -621,10 +629,9 @@ void msg_StackSet( int i_code, const char *psz_message, ... ) ...@@ -621,10 +629,9 @@ void msg_StackSet( int i_code, const char *psz_message, ... )
if( p_ctx == NULL ) if( p_ctx == NULL )
return; return;
va_start( ap, psz_message );
free( p_ctx->psz_message ); free( p_ctx->psz_message );
va_start( ap, psz_message );
if( vasprintf( &p_ctx->psz_message, psz_message, ap ) == -1 ) if( vasprintf( &p_ctx->psz_message, psz_message, ap ) == -1 )
p_ctx->psz_message = NULL; p_ctx->psz_message = NULL;
va_end( ap ); va_end( ap );
......
...@@ -145,7 +145,7 @@ int vlc_threads_init( void ) ...@@ -145,7 +145,7 @@ int vlc_threads_init( void )
} }
/* We should be safe now. Do all the initialization stuff we want. */ /* 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++; i_initializations++;
...@@ -173,7 +173,10 @@ void vlc_threads_end( void ) ...@@ -173,7 +173,10 @@ void vlc_threads_end( void )
assert( i_initializations > 0 ); assert( i_initializations > 0 );
if( i_initializations == 1 ) if( i_initializations == 1 )
{
vlc_object_release( p_root ); vlc_object_release( p_root );
vlc_threadvar_delete( &msg_context_global_key );
}
i_initializations--; i_initializations--;
#if defined( LIBVLC_USE_PTHREAD ) #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 ...@@ -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 * 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 ) #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 ) #elif defined( UNDER_CE )
i_ret = ENOSYS;
#elif defined( WIN32 ) #elif defined( WIN32 )
*p_tls = TlsAlloc(); *p_tls = TlsAlloc();
i_ret = (*p_tls == TLS_OUT_OF_INDEXES) ? EAGAIN : 0; i_ret = (*p_tls == TLS_OUT_OF_INDEXES) ? EAGAIN : 0;
...@@ -390,6 +394,18 @@ int __vlc_threadvar_create( vlc_threadvar_t *p_tls ) ...@@ -390,6 +394,18 @@ int __vlc_threadvar_create( vlc_threadvar_t *p_tls )
return i_ret; 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 * vlc_thread_create: create a thread, inner version
***************************************************************************** *****************************************************************************
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment