[vlc-commits] commit: Revert "vlc_clone_detach: remove thread handle parameter" ( =?UTF-8?Q?R=C3=A9mi=20Denis=2DCourmont=20?=)
git at videolan.org
git at videolan.org
Sun Dec 5 18:12:52 CET 2010
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Dec 5 19:12:38 2010 +0200| [757e6a6eb00f3c99335e5925e6ade4929b68d9ad] | committer: Rémi Denis-Courmont
Revert "vlc_clone_detach: remove thread handle parameter"
This reverts commit 653a66372d98131ab4c3f86bbf1d4786222d4c4c.
Conflicts:
src/win32/thread.c
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=757e6a6eb00f3c99335e5925e6ade4929b68d9ad
---
src/libvlc.h | 2 +-
src/misc/pthread.c | 14 ++++++++++----
src/playlist/fetcher.c | 3 ++-
src/playlist/preparser.c | 3 ++-
src/win32/thread.c | 21 ++++++++++++++++-----
5 files changed, 31 insertions(+), 12 deletions(-)
diff --git a/src/libvlc.h b/src/libvlc.h
index abbc1ac..82a05d0 100644
--- a/src/libvlc.h
+++ b/src/libvlc.h
@@ -52,7 +52,7 @@ void system_End ( libvlc_int_t * );
*/
/* This cannot be used as is from plugins yet: */
-int vlc_clone_detach (void *(*)(void *), void *, int);
+int vlc_clone_detach (vlc_thread_t *, void *(*)(void *), void *, int);
/* Hopefully, no need to export this. There is a new thread API instead. */
void vlc_thread_cancel (vlc_object_t *);
diff --git a/src/misc/pthread.c b/src/misc/pthread.c
index abf1c9f..6512c2e 100644
--- a/src/misc/pthread.c
+++ b/src/misc/pthread.c
@@ -717,7 +717,8 @@ void vlc_join (vlc_thread_t handle, void **result)
* Creates and starts new detached thread.
* A detached thread cannot be joined. Its resources will be automatically
* released whenever the thread exits (in particular, its call stack will be
- * reclaimed).
+ * reclaimed). Nevertheless, a detached thread may
+ * be cancelled; this can expedite its termination.
*
* Detached thread are particularly useful when some work needs to be done
* asynchronously, that is likely to be completed much earlier than the thread
@@ -730,19 +731,24 @@ void vlc_join (vlc_thread_t handle, void **result)
* thread. In practice, LibVLC will wait for detached threads to exit before
* it unloads the plugins.
*
+ * @param th [OUT] pointer to hold the thread handle, or NULL
* @param entry entry point for the thread
* @param data data parameter given to the entry point
* @param priority thread priority value
* @return 0 on success, a standard error code on error.
*/
-int vlc_clone_detach (void *(*entry) (void *), void *data, int priority)
+int vlc_clone_detach (vlc_thread_t *th, void *(*entry) (void *), void *data,
+ int priority)
{
- vlc_thread_t th;
+ vlc_thread_t dummy;
pthread_attr_t attr;
+ if (th == NULL)
+ th = &dummy;
+
pthread_attr_init (&attr);
pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
- return vlc_clone_attr (&th, &attr, entry, data, priority);
+ return vlc_clone_attr (th, &attr, entry, data, priority);
}
/**
diff --git a/src/playlist/fetcher.c b/src/playlist/fetcher.c
index 00f1137..2113d42 100644
--- a/src/playlist/fetcher.c
+++ b/src/playlist/fetcher.c
@@ -91,7 +91,8 @@ void playlist_fetcher_Push( playlist_fetcher_t *p_fetcher,
p_fetcher->i_waiting, p_item );
if( !p_fetcher->b_live )
{
- if( vlc_clone_detach( Thread, p_fetcher, VLC_THREAD_PRIORITY_LOW ) )
+ if( vlc_clone_detach( NULL, Thread, p_fetcher,
+ VLC_THREAD_PRIORITY_LOW ) )
msg_Err( p_fetcher->p_playlist,
"cannot spawn secondary preparse thread" );
else
diff --git a/src/playlist/preparser.c b/src/playlist/preparser.c
index d2bf99f..dfd955a 100644
--- a/src/playlist/preparser.c
+++ b/src/playlist/preparser.c
@@ -83,7 +83,8 @@ void playlist_preparser_Push( playlist_preparser_t *p_preparser, input_item_t *p
p_preparser->i_waiting, p_item );
if( !p_preparser->b_live )
{
- if( vlc_clone_detach( Thread, p_preparser, VLC_THREAD_PRIORITY_LOW ) )
+ if( vlc_clone_detach( NULL, Thread, p_preparser,
+ VLC_THREAD_PRIORITY_LOW ) )
msg_Warn( p_preparser->p_playlist,
"cannot spawn pre-parser thread" );
else
diff --git a/src/win32/thread.c b/src/win32/thread.c
index 99c4e94..2a18c5c 100644
--- a/src/win32/thread.c
+++ b/src/win32/thread.c
@@ -563,15 +563,15 @@ static unsigned __stdcall vlc_entry (void *p)
return 0;
}
-int vlc_clone (vlc_thread_t *p_handle, void * (*entry) (void *), void *data,
- int priority)
+static int vlc_clone_attr (vlc_thread_t *p_handle, bool detached,
+ void *(*entry) (void *), void *data, int priority)
{
struct vlc_thread *th = malloc (sizeof (*th));
if (unlikely(th == NULL))
return ENOMEM;
th->entry = entry;
th->data = data;
- th->detached = p_handle == NULL;
+ th->detached = detached;
th->killable = false; /* not until vlc_entry() ! */
th->killed = false;
th->cleaners = NULL;
@@ -623,6 +623,12 @@ int vlc_clone (vlc_thread_t *p_handle, void * (*entry) (void *), void *data,
return 0;
}
+int vlc_clone (vlc_thread_t *p_handle, void *(*entry) (void *),
+ void *data, int priority)
+{
+ return vlc_clone_attr (p_handle, false, entry, data, prioity);
+}
+
void vlc_join (vlc_thread_t th, void **result)
{
do
@@ -639,9 +645,14 @@ void vlc_join (vlc_thread_t th, void **result)
free (th);
}
-int vlc_clone_detach (void *(*entry) (void *), void *data, int priority)
+int vlc_clone_detach (vlc_thread_t *p_handle, void *(*entry) (void *),
+ void *data, int priority)
{
- return vlc_clone (NULL, entry, data, priority);
+ vlc_thread_t th;
+ if (p_handle == NULL)
+ p_handle = &th;
+
+ return vlc_clone_attr (p_handle, true, entry, data, priority);
}
/*** Thread cancellation ***/
More information about the vlc-commits
mailing list