[vlc-devel] commit: Deinline vlc_threadvar_(|s)get and kill useless indirection ( Rémi Denis-Courmont )
git version control
git at videolan.org
Sat Apr 11 20:04:57 CEST 2009
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Apr 11 20:10:14 2009 +0300| [31196681e079413f491febb8eabf996f4e2b445a] | committer: Rémi Denis-Courmont
Deinline vlc_threadvar_(|s)get and kill useless indirection
I wonder if we should unexport threadvar functions? In any case, they
are not used from outside libvlccore at the moment.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=31196681e079413f491febb8eabf996f4e2b445a
---
include/vlc_threads.h | 38 ++------------------------------------
src/libvlccore.sym | 2 ++
src/misc/messages.c | 4 ++--
src/misc/threads.c | 48 +++++++++++++++++++++++++++++++++++++++++-------
4 files changed, 47 insertions(+), 45 deletions(-)
diff --git a/include/vlc_threads.h b/include/vlc_threads.h
index 6a6baca..71a8dbe 100644
--- a/include/vlc_threads.h
+++ b/include/vlc_threads.h
@@ -153,6 +153,8 @@ VLC_EXPORT( void, vlc_cond_wait, (vlc_cond_t *, vlc_mutex_t *) );
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 * ) );
@@ -234,42 +236,6 @@ static inline void vlc_cleanup_lock (void *lock)
}
#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;
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index cb6c85b..3e04bb6 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -491,6 +491,8 @@ __vlc_thread_join
__vlc_thread_set_priority
vlc_threadvar_create
vlc_threadvar_delete
+vlc_threadvar_get
+vlc_threadvar_set
vlc_ureduce
VLC_Version
vlc_wclosedir
diff --git a/src/misc/messages.c b/src/misc/messages.c
index 190ec7d..a453bcc 100644
--- a/src/misc/messages.c
+++ b/src/misc/messages.c
@@ -599,14 +599,14 @@ static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item )
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;
}
diff --git a/src/misc/threads.c b/src/misc/threads.c
index 1b2f25e..75aed70 100644
--- a/src/misc/threads.c
+++ b/src/misc/threads.c
@@ -170,7 +170,7 @@ static void CALLBACK vlc_cancel_self (ULONG_PTR dummy);
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 */
@@ -674,6 +674,40 @@ void vlc_threadvar_delete (vlc_threadvar_t *p_tls)
#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)
@@ -684,7 +718,7 @@ 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;
}
@@ -904,7 +938,7 @@ int vlc_savecancel (void)
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 */
@@ -938,7 +972,7 @@ void vlc_restorecancel (int state)
# 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)
@@ -963,7 +997,7 @@ void vlc_testcancel (void)
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 */
@@ -1199,7 +1233,7 @@ void vlc_control_cancel (int cmd, ...)
#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
@@ -1210,7 +1244,7 @@ void vlc_control_cancel (int cmd, ...)
if (nfo == NULL)
return; /* Uho! Expect problems! */
*nfo = VLC_CANCEL_INIT;
- vlc_threadvar_set (&cancel_key, nfo);
+ vlc_threadvar_set (cancel_key, nfo);
#endif
}
More information about the vlc-devel
mailing list