]> git.sesse.net Git - vlc/commitdiff
Win32: no need to put thread function into vlc_thread_t
authorRémi Denis-Courmont <remi@remlab.net>
Sat, 1 Aug 2009 20:44:36 +0000 (23:44 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Sun, 2 Aug 2009 06:27:12 +0000 (09:27 +0300)
include/vlc_threads.h
src/misc/w32thread.c

index 7b7a5b7f74430bce9ffb4d4f08ca59698d66f9e7..55fea78859083b0ff7a35f1b46b017d37fbb82fb 100644 (file)
@@ -129,8 +129,7 @@ struct vlc_timer_t
 typedef struct
 {
     HANDLE handle;
-    void  *(*entry) (void *);
-    void  *data;
+    void  *result;
 #if defined( UNDER_CE )
     HANDLE cancel_event;
 #endif
index b3697334a3f6d7ec95577813360fbfd1ca80e757..e0e06a717ebdc8e47cb6f401e835e060170cede1 100644 (file)
@@ -407,16 +407,27 @@ void vlc_threads_setup (libvlc_int_t *p_libvlc)
     (void) p_libvlc;
 }
 
-static unsigned __stdcall vlc_entry (void *data)
+struct vlc_entry_data
+{
+    vlc_thread_t handle;
+    void *     (*func) (void *);
+    void *       data;
+};
+
+static unsigned __stdcall vlc_entry (void *p)
 {
     vlc_cancel_t cancel_data = VLC_CANCEL_INIT;
-    vlc_thread_t self = data;
+    struct vlc_entry_data data;
+
+    memcpy (&data, p, sizeof (data));
+    free (p);
+
 #ifdef UNDER_CE
-    cancel_data.cancel_event = self->cancel_event;
+    cancel_data.cancel_event = data.handle->cancel_event;
 #endif
 
     vlc_threadvar_set (cancel_key, &cancel_data);
-    self->data = self->entry (self->data);
+    data.handle->result = data.func (data.data);
     return 0;
 }
 
@@ -433,19 +444,28 @@ int vlc_clone (vlc_thread_t *p_handle, void * (*entry) (void *), void *data,
     if (th == NULL)
         return ENOMEM;
 
-    th->data = data;
-    th->entry = entry;
+    struct vlc_entry_data *entry_data = malloc (sizeof (*entry_data));
+    if (entry_data == NULL)
+    {
+        free (th);
+        return ENOMEM;
+    }
+    entry_data->handle = th;
+    entry_data->func = entry;
+    entry_data->data = data;
+
 #if defined( UNDER_CE )
     th->cancel_event = CreateEvent (NULL, FALSE, FALSE, NULL);
     if (th->cancel_event == NULL)
     {
         free(th);
+        free (entry_data);
         return errno;
     }
-    hThread = CreateThread (NULL, 128*1024, vlc_entry, th, CREATE_SUSPENDED, NULL);
+    hThread = CreateThread (NULL, 128*1024, vlc_entry, entry_data, CREATE_SUSPENDED, NULL);
 #else
     hThread = (HANDLE)(uintptr_t)
-        _beginthreadex (NULL, 0, vlc_entry, th, CREATE_SUSPENDED, NULL);
+        _beginthreadex (NULL, 0, vlc_entry, entry_data, CREATE_SUSPENDED, NULL);
 #endif
 
     if (hThread)
@@ -459,6 +479,7 @@ int vlc_clone (vlc_thread_t *p_handle, void * (*entry) (void *), void *data,
         {
             CloseHandle (hThread);
             free (th);
+            free (entry_data);
             return ENOMEM;
         }
 #else
@@ -485,7 +506,7 @@ void vlc_join (vlc_thread_t handle, void **result)
 
     CloseHandle (handle->handle);
     if (result)
-        *result = handle->data;
+        *result = handle->result;
 #ifdef UNDER_CE
     CloseHandle (handle->cancel_event);
 #endif