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

Win32: remove live loop and bogus atomic variable

That inexplicably got merged even though it was rejected upon review.
This simplification follows afe774e0.
parent 92164492
...@@ -414,9 +414,8 @@ static vlc_threadvar_t thread_key; ...@@ -414,9 +414,8 @@ static vlc_threadvar_t thread_key;
/** Per-thread data */ /** Per-thread data */
struct vlc_thread struct vlc_thread
{ {
atomic_uintptr_t id; HANDLE id;
bool detached;
bool killable; bool killable;
atomic_bool killed; atomic_bool killed;
vlc_cleanup_t *cleaners; vlc_cleanup_t *cleaners;
...@@ -456,16 +455,8 @@ retry: ...@@ -456,16 +455,8 @@ retry:
} }
vlc_mutex_unlock (&super_mutex); vlc_mutex_unlock (&super_mutex);
if (th->detached) if (th->id == NULL) /* Detached thread */
{
HANDLE h;
do
h = (HANDLE) atomic_load(&th->id);
while (unlikely(!h)); /* Loop until _beginthreadex has returned */
CloseHandle (h);
free (th); free (th);
}
} }
static unsigned __stdcall vlc_entry (void *p) static unsigned __stdcall vlc_entry (void *p)
...@@ -487,37 +478,33 @@ static int vlc_clone_attr (vlc_thread_t *p_handle, bool detached, ...@@ -487,37 +478,33 @@ static int vlc_clone_attr (vlc_thread_t *p_handle, bool detached,
return ENOMEM; return ENOMEM;
th->entry = entry; th->entry = entry;
th->data = data; th->data = data;
th->detached = detached;
th->killable = false; /* not until vlc_entry() ! */ th->killable = false; /* not until vlc_entry() ! */
atomic_store(&th->killed, false); atomic_store(&th->killed, false);
atomic_store(&th->id, (uintptr_t) NULL);
th->cleaners = NULL; th->cleaners = NULL;
HANDLE hThread;
/* When using the MSVCRT C library you have to use the _beginthreadex /* When using the MSVCRT C library you have to use the _beginthreadex
* function instead of CreateThread, otherwise you'll end up with * function instead of CreateThread, otherwise you'll end up with
* memory leaks and the signal functions not working (see Microsoft * memory leaks and the signal functions not working (see Microsoft
* Knowledge Base, article 104641) */ * Knowledge Base, article 104641) */
uintptr_t h; uintptr_t h = _beginthreadex (NULL, 0, vlc_entry, th, 0, NULL);
h = _beginthreadex (NULL, 0, vlc_entry, th, 0, NULL);
if (h == 0) if (h == 0)
{ {
int err = errno; int err = errno;
free (th); free (th);
return err; return err;
} }
hThread = (HANDLE)h;
atomic_store(&th->id, (uintptr_t) hThread); if (detached)
CloseHandle((HANDLE)h);
else
th->id = (HANDLE)h;
if (p_handle != NULL) if (p_handle != NULL)
*p_handle = th; *p_handle = th;
#if !VLC_WINSTORE_APP #if !VLC_WINSTORE_APP
if (priority) if (priority)
SetThreadPriority (hThread, priority); SetThreadPriority (th->id, priority);
#endif #endif
return 0; return 0;
...@@ -531,15 +518,13 @@ int vlc_clone (vlc_thread_t *p_handle, void *(*entry) (void *), ...@@ -531,15 +518,13 @@ int vlc_clone (vlc_thread_t *p_handle, void *(*entry) (void *),
void vlc_join (vlc_thread_t th, void **result) void vlc_join (vlc_thread_t th, void **result)
{ {
HANDLE h = (HANDLE) atomic_load(&th->id);
do do
vlc_testcancel (); vlc_testcancel ();
while (vlc_WaitForSingleObject (h, INFINITE) == WAIT_IO_COMPLETION); while (vlc_WaitForSingleObject (th->id, INFINITE) == WAIT_IO_COMPLETION);
if (result != NULL) if (result != NULL)
*result = th->data; *result = th->data;
CloseHandle (h); CloseHandle (th->id);
free (th); free (th);
} }
...@@ -577,7 +562,7 @@ void vlc_cancel (vlc_thread_t th) ...@@ -577,7 +562,7 @@ void vlc_cancel (vlc_thread_t th)
{ {
atomic_store(&th->killed, true); atomic_store(&th->killed, true);
#if !VLC_WINSTORE_APP #if !VLC_WINSTORE_APP
QueueUserAPC (dummy_apc, atomic_load(&th->id), 0); QueueUserAPC (dummy_apc, th->id, 0);
#endif #endif
} }
......
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