Commit b0e76ef9 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Android: avoid polling timer in vlc_join()

parent d611f5c6
...@@ -168,12 +168,12 @@ struct vlc_thread ...@@ -168,12 +168,12 @@ struct vlc_thread
pthread_t thread; pthread_t thread;
pthread_cond_t *cond; /// Non-null if thread waiting on cond pthread_cond_t *cond; /// Non-null if thread waiting on cond
vlc_mutex_t lock ; /// Protects cond vlc_mutex_t lock ; /// Protects cond
vlc_sem_t finished;
void *(*entry)(void*); void *(*entry)(void*);
void *data; void *data;
vlc_atomic_t killed; vlc_atomic_t killed;
vlc_atomic_t finished;
bool killable; bool killable;
}; };
...@@ -283,7 +283,7 @@ static void *joinable_thread(void *data) ...@@ -283,7 +283,7 @@ static void *joinable_thread(void *data)
thread = th; thread = th;
ret = th->entry(th->data); ret = th->entry(th->data);
vlc_atomic_set(&th->finished, true); vlc_sem_post(&th->finished);
return ret; return ret;
} }
...@@ -309,8 +309,9 @@ static int vlc_clone_attr (vlc_thread_t *th, void *(*entry) (void *), ...@@ -309,8 +309,9 @@ static int vlc_clone_attr (vlc_thread_t *th, void *(*entry) (void *),
pthread_sigmask (SIG_BLOCK, &set, &oldset); pthread_sigmask (SIG_BLOCK, &set, &oldset);
} }
vlc_sem_init(&thread->finished, 0);
vlc_atomic_set(&thread->killed, false); vlc_atomic_set(&thread->killed, false);
vlc_atomic_set(&thread->finished, false);
thread->killable = true; thread->killable = true;
thread->cond = NULL; thread->cond = NULL;
thread->entry = entry; thread->entry = entry;
...@@ -340,9 +341,8 @@ int vlc_clone (vlc_thread_t *th, void *(*entry) (void *), void *data, ...@@ -340,9 +341,8 @@ int vlc_clone (vlc_thread_t *th, void *(*entry) (void *), void *data,
void vlc_join (vlc_thread_t handle, void **result) void vlc_join (vlc_thread_t handle, void **result)
{ {
vlc_testcancel(); vlc_sem_wait (&handle->finished);
while (!vlc_atomic_get(&handle->finished)) vlc_sem_destroy (&handle->finished);
msleep(CLOCK_FREQ / 100);
int val = pthread_join (handle->thread, result); int val = pthread_join (handle->thread, result);
VLC_THREAD_ASSERT ("joining thread"); VLC_THREAD_ASSERT ("joining thread");
...@@ -406,7 +406,7 @@ void vlc_testcancel (void) ...@@ -406,7 +406,7 @@ void vlc_testcancel (void)
if (!vlc_atomic_get(&thread->killed)) if (!vlc_atomic_get(&thread->killed))
return; return;
vlc_atomic_set(&thread->finished, true); vlc_sem_post(&thread->finished);
#warning FIXME: memory leak for detached threads #warning FIXME: memory leak for detached threads
pthread_exit(NULL); pthread_exit(NULL);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment