[vlc-devel] commit: Win32: privatize vlc_timer layout too ( Rémi Denis-Courmont )

git version control git at videolan.org
Sun Aug 2 14:30:17 CEST 2009


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Aug  2 15:01:04 2009 +0300| [c159f79f2a5b00556347d302e9fb8221cfb0d7fe] | committer: Rémi Denis-Courmont 

Win32: privatize vlc_timer layout too

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

 include/vlc_threads.h |    9 +--------
 src/misc/w32thread.c  |   41 +++++++++++++++++++++++++++++------------
 2 files changed, 30 insertions(+), 20 deletions(-)

diff --git a/include/vlc_threads.h b/include/vlc_threads.h
index 1e4324f..eb27c49 100644
--- a/include/vlc_threads.h
+++ b/include/vlc_threads.h
@@ -134,14 +134,7 @@ typedef struct
 } vlc_rwlock_t;
 
 typedef DWORD   vlc_threadvar_t;
-typedef struct vlc_timer_t vlc_timer_t;
-struct vlc_timer_t
-{
-    HANDLE handle;
-    void (*func) (void *);
-    void *data;
-};
-
+typedef struct vlc_timer *vlc_timer_t;
 #endif
 
 #if defined( WIN32 ) && !defined ETIMEDOUT
diff --git a/src/misc/w32thread.c b/src/misc/w32thread.c
index 5b337e4..c461090 100644
--- a/src/misc/w32thread.c
+++ b/src/misc/w32thread.c
@@ -601,35 +601,52 @@ void vlc_control_cancel (int cmd, ...)
 
 
 /*** Timers ***/
+struct vlc_timer
+{
+    HANDLE handle;
+    void (*func) (void *);
+    void *data;
+};
+
 static void CALLBACK vlc_timer_do (void *val, BOOLEAN timeout)
 {
-    vlc_timer_t *id = val;
+    struct vlc_timer *timer = val;
 
     assert (timeout);
-    id->func (id->data);
+    timer->func (timer->data);
 }
 
 int vlc_timer_create (vlc_timer_t *id, void (*func) (void *), void *data)
 {
-    id->func = func;
-    id->data = data;
-    id->handle = INVALID_HANDLE_VALUE;
+    struct vlc_timer *timer = malloc (sizeof (*timer));
+
+    if (timer == NULL)
+        return ENOMEM;
+    timer->func = func;
+    timer->data = data;
+    timer->handle = INVALID_HANDLE_VALUE;
+    *id = timer;
     return 0;
 }
 
 void vlc_timer_destroy (vlc_timer_t *id)
 {
-    if (id->handle != INVALID_HANDLE_VALUE)
-        DeleteTimerQueueTimer (NULL, id->handle, INVALID_HANDLE_VALUE);
+    struct vlc_timer *timer = *id;
+
+    if (timer->handle != INVALID_HANDLE_VALUE)
+        DeleteTimerQueueTimer (NULL, timer->handle, INVALID_HANDLE_VALUE);
+    free (timer);
 }
 
 void vlc_timer_schedule (vlc_timer_t *id, bool absolute,
                          mtime_t value, mtime_t interval)
 {
-    if (id->handle != INVALID_HANDLE_VALUE)
+    struct vlc_timer *timer = *id;
+
+    if (timer->handle != INVALID_HANDLE_VALUE)
     {
-        DeleteTimerQueueTimer (NULL, id->handle, NULL);
-        id->handle = INVALID_HANDLE_VALUE;
+        DeleteTimerQueueTimer (NULL, timer->handle, NULL);
+        timer->handle = INVALID_HANDLE_VALUE;
     }
     if (value == 0)
         return; /* Disarm */
@@ -638,8 +655,8 @@ void vlc_timer_schedule (vlc_timer_t *id, bool absolute,
         value -= mdate ();
     value = (value + 999) / 1000;
     interval = (interval + 999) / 1000;
-    if (!CreateTimerQueueTimer (&id->handle, NULL, vlc_timer_do, id, value,
-                                interval, WT_EXECUTEDEFAULT))
+    if (!CreateTimerQueueTimer (&timer->handle, NULL, vlc_timer_do, timer,
+                                value, interval, WT_EXECUTEDEFAULT))
         abort ();
 }
 




More information about the vlc-devel mailing list