[vlc-devel] commit: Fix vlc_thread_ready invalid use of object_wait ( Rémi Denis-Courmont )
git version control
git at videolan.org
Sat Oct 4 22:22:02 CEST 2008
vlc | branch: master | Rémi Denis-Courmont <rdenis at simphalempin.com> | Sat Oct 4 23:21:35 2008 +0300| [43b5fcef1b26f16914028b5954a846aff685c881] | committer: Rémi Denis-Courmont
Fix vlc_thread_ready invalid use of object_wait
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=43b5fcef1b26f16914028b5954a846aff685c881
---
include/vlc_threads.h | 3 ++-
src/libvlc.h | 9 +++++++++
src/libvlccore.sym | 1 +
src/misc/threads.c | 40 +++++++++++++++++++++++++++++++---------
4 files changed, 43 insertions(+), 10 deletions(-)
diff --git a/include/vlc_threads.h b/include/vlc_threads.h
index 4cd9827..374d01d 100644
--- a/include/vlc_threads.h
+++ b/include/vlc_threads.h
@@ -166,7 +166,8 @@ enum {
};
#endif
-#define vlc_thread_ready vlc_object_signal
+VLC_EXPORT(void, vlc_thread_ready, (vlc_object_t *obj));
+#define vlc_thread_ready(o) vlc_thread_ready(VLC_OBJECT(o))
/**
* Save the cancellation state and disable cancellation for the calling thread.
diff --git a/src/libvlc.h b/src/libvlc.h
index 9cec259..6cd9a0d 100644
--- a/src/libvlc.h
+++ b/src/libvlc.h
@@ -149,6 +149,10 @@ extern module_bank_t *p_module_bank;
extern char *psz_vlcpath;
+#ifdef LIBVLC_USE_PTHREAD
+# include <semaphore.h> /* TODO: get rid of vlc_thread_ready and this */
+#endif
+
/**
* Private LibVLC data for each object.
*/
@@ -162,6 +166,11 @@ typedef struct vlc_object_internals_t
/* Thread properties, if any */
vlc_thread_t thread_id;
bool b_thread;
+#ifdef LIBVLC_USE_PTHREAD
+ sem_t thread_ready;
+#elif defined (WIN32)
+ HANDLE thread_ready;
+#endif
/* Objects thread synchronization */
vlc_mutex_t lock;
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index ce068e0..300e5dd 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -504,6 +504,7 @@ vlc_strtoll
vlc_submodule_create
__vlc_thread_create
__vlc_thread_join
+vlc_thread_ready
__vlc_thread_set_priority
vlc_threadvar_create
vlc_threadvar_delete
diff --git a/src/misc/threads.c b/src/misc/threads.c
index 58a4cb1..5a638f2 100644
--- a/src/misc/threads.c
+++ b/src/misc/threads.c
@@ -802,12 +802,12 @@ int __vlc_thread_create( vlc_object_t *p_this, const char * psz_file, int i_line
boot->entry = func;
boot->object = p_this;
- vlc_object_lock( p_this );
-
/* Make sure we don't re-create a thread if the object has already one */
assert( !p_priv->b_thread );
#if defined( LIBVLC_USE_PTHREAD )
+ if (b_wait)
+ sem_init (&p_priv->thread_ready, 0, 0);
#ifndef __APPLE__
if( config_GetInt( p_this, "rt-priority" ) > 0 )
#endif
@@ -816,33 +816,55 @@ int __vlc_thread_create( vlc_object_t *p_this, const char * psz_file, int i_line
if( config_GetType( p_this, "rt-offset" ) )
i_priority += config_GetInt( p_this, "rt-offset" );
}
+#elif defined (WIN32)
+ if (b_wait)
+ p_priv->thread_ready = CreateEvent (NULL, TRUE, FALSE, NULL);
#endif
+ p_priv->b_thread = true;
i_ret = vlc_clone( &p_priv->thread_id, thread_entry, boot, i_priority );
if( i_ret == 0 )
{
+ msg_Dbg( p_this, "thread %lu (%s) created at priority %d (%s:%d)",
+ (unsigned long)p_priv->thread_id, psz_name, i_priority,
+ psz_file, i_line );
if( b_wait )
{
msg_Dbg( p_this, "waiting for thread initialization" );
- vlc_object_wait( p_this );
+#if defined (LIBVLC_USE_PTHREAD)
+ sem_wait (&p_priv->thread_ready);
+ sem_destroy (&p_priv->thread_ready);
+#elif defined (WIN32)
+ WaitForSingleObject (p_priv->thread_ready, INFINITE);
+ CloseHandle (p_priv->thread_ready);
+#endif
}
-
- p_priv->b_thread = true;
- msg_Dbg( p_this, "thread %lu (%s) created at priority %d (%s:%d)",
- (unsigned long)p_priv->thread_id, psz_name, i_priority,
- psz_file, i_line );
}
else
{
+ p_priv->b_thread = false;
errno = i_ret;
msg_Err( p_this, "%s thread could not be created at %s:%d (%m)",
psz_name, psz_file, i_line );
}
- vlc_object_unlock( p_this );
return i_ret;
}
+#undef vlc_thread_ready
+void vlc_thread_ready (vlc_object_t *obj)
+{
+ vlc_object_internals_t *priv = vlc_internals (obj);
+
+ assert (priv->b_thread);
+#if defined (LIBVLC_USE_PTHREAD)
+ assert (pthread_equal (pthread_self (), priv->thread_id));
+ sem_post (&priv->thread_ready);
+#elif defined (WIN32)
+ SetEvent (priv->thread_ready);
+#endif
+}
+
/*****************************************************************************
* vlc_thread_set_priority: set the priority of the current thread when we
* couldn't set it in vlc_thread_create (for instance for the main thread)
More information about the vlc-devel
mailing list