+/*****************************************************************************
+ * vlc_threadvar_create: create a thread-local variable
+ *****************************************************************************/
+#define vlc_threadvar_create( PTHIS, P_TLS ) \
+ __vlc_threadvar_create( PTHIS, 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 )
+{
+ int i_ret;
+
+#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 );
+
+#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
+ i_ret = pthread_setspecific( p_tls->handle, p_value );
+
+#elif defined( HAVE_CTHREADS_H )
+ i_ret = cthread_setspecific( p_tls->handle, p_value );
+#endif
+
+ return i_ret;
+}
+
+/*****************************************************************************
+ * vlc_threadvar_get: create: get the value of a thread-local variable
+ *****************************************************************************/
+static inline void* vlc_threadvar_get( vlc_threadvar_t * p_tls )
+{
+ void* p_ret;
+
+#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 );
+
+#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
+ p_ret = pthread_getspecific( p_tls->handle );
+
+#elif defined( HAVE_CTHREADS_H )
+ if ( !cthread_getspecific( p_tls->handle, &p_ret ) )
+ {
+ p_ret = NULL;
+ }
+#endif
+
+ return p_ret;
+}
+