[vlc-devel] commit: Win32: make vlc_thread_t a plain HANDLE (no heap alloc) ( Rémi Denis-Courmont )

git version control git at videolan.org
Sun Aug 2 08:53:51 CEST 2009


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Aug  1 23:58:39 2009 +0300| [f18b184824b0b2cbef6df1569d36f1a56d6d7c92] | committer: Rémi Denis-Courmont 

Win32: make vlc_thread_t a plain HANDLE (no heap alloc)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f18b184824b0b2cbef6df1569d36f1a56d6d7c92
---

 include/vlc_threads.h |    8 +-------
 src/misc/w32thread.c  |   27 ++++++---------------------
 2 files changed, 7 insertions(+), 28 deletions(-)

diff --git a/include/vlc_threads.h b/include/vlc_threads.h
index fd00fd2..58b337f 100644
--- a/include/vlc_threads.h
+++ b/include/vlc_threads.h
@@ -126,13 +126,7 @@ struct vlc_timer_t
 };
 
 #elif defined( WIN32 )
-typedef struct
-{
-    HANDLE handle;
-#if defined( UNDER_CE )
-    HANDLE cancel_event;
-#endif
-} *vlc_thread_t;
+typedef HANDLE vlc_thread_t;
 
 typedef struct
 {
diff --git a/src/misc/w32thread.c b/src/misc/w32thread.c
index afbacfa..bf806f9 100644
--- a/src/misc/w32thread.c
+++ b/src/misc/w32thread.c
@@ -409,9 +409,8 @@ void vlc_threads_setup (libvlc_int_t *p_libvlc)
 
 struct vlc_entry_data
 {
-    vlc_thread_t handle;
-    void *     (*func) (void *);
-    void *       data;
+    void * (*func) (void *);
+    void *  data;
 };
 
 static unsigned __stdcall vlc_entry (void *p)
@@ -439,18 +438,10 @@ int vlc_clone (vlc_thread_t *p_handle, void * (*entry) (void *), void *data,
      * memory leaks and the signal functions not working (see Microsoft
      * Knowledge Base, article 104641) */
     HANDLE hThread;
-    vlc_thread_t th = malloc (sizeof (*th));
-
-    if (th == NULL)
-        return ENOMEM;
 
     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;
 
@@ -458,7 +449,6 @@ int vlc_clone (vlc_thread_t *p_handle, void * (*entry) (void *), void *data,
     th->cancel_event = CreateEvent (NULL, FALSE, FALSE, NULL);
     if (th->cancel_event == NULL)
     {
-        free(th);
         free (entry_data);
         return errno;
     }
@@ -474,11 +464,10 @@ int vlc_clone (vlc_thread_t *p_handle, void * (*entry) (void *), void *data,
         /* Thread closes the handle when exiting, duplicate it here
          * to be on the safe side when joining. */
         if (!DuplicateHandle (GetCurrentProcess (), hThread,
-                              GetCurrentProcess (), &th->handle, 0, FALSE,
+                              GetCurrentProcess (), p_handle, 0, FALSE,
                               DUPLICATE_SAME_ACCESS))
         {
             CloseHandle (hThread);
-            free (th);
             free (entry_data);
             return ENOMEM;
         }
@@ -489,11 +478,8 @@ int vlc_clone (vlc_thread_t *p_handle, void * (*entry) (void *), void *data,
         ResumeThread (hThread);
         if (priority)
             SetThreadPriority (hThread, priority);
-
-        *p_handle = th;
         return 0;
     }
-    free (th);
     return errno;
 }
 
@@ -501,15 +487,14 @@ void vlc_join (vlc_thread_t handle, void **result)
 {
     do
         vlc_testcancel ();
-    while (WaitForSingleObjectEx (handle->handle, INFINITE, TRUE)
+    while (WaitForSingleObjectEx (handle, INFINITE, TRUE)
                                                         == WAIT_IO_COMPLETION);
 
-    CloseHandle (handle->handle);
+    CloseHandle (handle);
     assert (result == NULL); /* <- FIXME if ever needed */
 #ifdef UNDER_CE
     CloseHandle (handle->cancel_event);
 #endif
-    free (handle);
 }
 
 
@@ -525,7 +510,7 @@ static void CALLBACK vlc_cancel_self (ULONG_PTR dummy)
 void vlc_cancel (vlc_thread_t thread_id)
 {
 #ifndef UNDER_CE
-    QueueUserAPC (vlc_cancel_self, thread_id->handle, 0);
+    QueueUserAPC (vlc_cancel_self, thread_id, 0);
 #else
     SetEvent (thread_id->cancel_event);
 #endif




More information about the vlc-devel mailing list