VLC_EXPORT( int, vlc_cond_timedwait, (vlc_cond_t *, vlc_mutex_t *, mtime_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_threadvar_set, (vlc_threadvar_t, void *) );
+VLC_EXPORT( void *, vlc_threadvar_get, (vlc_threadvar_t) );
VLC_EXPORT( int, vlc_thread_create, ( vlc_object_t *, const char *, int, const char *, void * ( * ) ( vlc_object_t * ), int ) );
VLC_EXPORT( int, __vlc_thread_set_priority, ( vlc_object_t *, const char *, int, int ) );
VLC_EXPORT( void, __vlc_thread_join, ( vlc_object_t * ) );
}
#define mutex_cleanup_push( lock ) vlc_cleanup_push (vlc_cleanup_lock, lock)
-/*****************************************************************************
- * 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(LIBVLC_USE_PTHREAD)
- i_ret = pthread_setspecific( *p_tls, p_value );
-
-#elif defined( UNDER_CE ) || defined( WIN32 )
- i_ret = TlsSetValue( *p_tls, p_value ) ? EINVAL : 0;
-
-#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(LIBVLC_USE_PTHREAD)
- p_ret = pthread_getspecific( *p_tls );
-
-#elif defined( UNDER_CE ) || defined( WIN32 )
- p_ret = TlsGetValue( *p_tls );
-
-#endif
-
- return p_ret;
-}
-
# if defined (_POSIX_SPIN_LOCKS) && ((_POSIX_SPIN_LOCKS - 0) > 0)
typedef pthread_spinlock_t vlc_spinlock_t;
__vlc_thread_set_priority
vlc_threadvar_create
vlc_threadvar_delete
+vlc_threadvar_get
+vlc_threadvar_set
vlc_ureduce
VLC_Version
vlc_wclosedir
static msg_context_t* GetContext(void)
{
- msg_context_t *p_ctx = vlc_threadvar_get( &msg_context );
+ msg_context_t *p_ctx = vlc_threadvar_get( msg_context );
if( p_ctx == NULL )
{
p_ctx = malloc( sizeof( msg_context_t ) );
if( !p_ctx )
return NULL;
p_ctx->psz_message = NULL;
- vlc_threadvar_set( &msg_context, p_ctx );
+ vlc_threadvar_set( msg_context, p_ctx );
}
return p_ctx;
}
static DWORD vlc_cancelable_wait (DWORD count, const HANDLE *handles,
DWORD delay)
{
- vlc_cancel_t *nfo = vlc_threadvar_get (&cancel_key);
+ vlc_cancel_t *nfo = vlc_threadvar_get (cancel_key);
if (nfo == NULL)
{
/* Main thread - cannot be cancelled anyway */
#endif
}
+/**
+ * Sets a thread-local variable.
+ * @param key thread-local variable key (created with vlc_threadvar_create())
+ * @param value new value for the variable for the calling thread
+ * @return 0 on success, a system error code otherwise.
+ */
+int vlc_threadvar_set (vlc_threadvar_t key, void *value)
+{
+#if defined(LIBVLC_USE_PTHREAD)
+ return pthread_setspecific (key, value);
+#elif defined( UNDER_CE ) || defined( WIN32 )
+ return TlsSetValue (key, p_value) ? ENOMEM : 0;
+#else
+# error Unimplemented!
+#endif
+}
+
+/**
+ * Gets the value of a thread-local variable for the calling thread.
+ * This function cannot fail.
+ * @return the value associated with the given variable for the calling
+ * or NULL if there is no value.
+ */
+void *vlc_threadvar_get (vlc_threadvar_t key)
+{
+#if defined(LIBVLC_USE_PTHREAD)
+ return pthread_getspecific (key);
+#elif defined( UNDER_CE ) || defined( WIN32 )
+ return TlsGetValue (key);
+#else
+# error Unimplemented!
+#endif
+}
+
#if defined (LIBVLC_USE_PTHREAD)
#elif defined (WIN32)
static unsigned __stdcall vlc_entry (void *data)
cancel_data.cancel_event = self->cancel_event;
#endif
- vlc_threadvar_set (&cancel_key, &cancel_data);
+ vlc_threadvar_set (cancel_key, &cancel_data);
self->data = self->entry (self->data);
return 0;
}
VLC_THREAD_ASSERT ("saving cancellation");
#else
- vlc_cancel_t *nfo = vlc_threadvar_get (&cancel_key);
+ vlc_cancel_t *nfo = vlc_threadvar_get (cancel_key);
if (nfo == NULL)
return false; /* Main thread - cannot be cancelled anyway */
# endif
#else
- vlc_cancel_t *nfo = vlc_threadvar_get (&cancel_key);
+ vlc_cancel_t *nfo = vlc_threadvar_get (cancel_key);
assert (state == false || state == true);
if (nfo == NULL)
pthread_testcancel ();
#else
- vlc_cancel_t *nfo = vlc_threadvar_get (&cancel_key);
+ vlc_cancel_t *nfo = vlc_threadvar_get (cancel_key);
if (nfo == NULL)
return; /* Main thread - cannot be cancelled anyway */
#else
va_list ap;
- vlc_cancel_t *nfo = vlc_threadvar_get (&cancel_key);
+ vlc_cancel_t *nfo = vlc_threadvar_get (cancel_key);
if (nfo == NULL)
{
#ifdef WIN32
if (nfo == NULL)
return; /* Uho! Expect problems! */
*nfo = VLC_CANCEL_INIT;
- vlc_threadvar_set (&cancel_key, nfo);
+ vlc_threadvar_set (cancel_key, nfo);
#endif
}