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 * ) );
#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
*****************************************************************************/
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
*/
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
__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
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;
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 );
}
/* 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++;
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 )
/*****************************************************************************
* 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;
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
*****************************************************************************