[vlc-commits] threads: vlc_thread_t is opaque

Rémi Denis-Courmont git at videolan.org
Mon Jul 25 21:00:03 CEST 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Jul 25 19:10:11 2016 +0300| [07bd730be5188e198af9cf5f965ae894a7acc542] | committer: Rémi Denis-Courmont

threads: vlc_thread_t is opaque

Comparison with zero means nothing.

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

 include/vlc_threads.h | 10 +++++++---
 src/posix/thread.c    | 15 ++++++++-------
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/include/vlc_threads.h b/include/vlc_threads.h
index 33b9b53..bf9132f 100644
--- a/include/vlc_threads.h
+++ b/include/vlc_threads.h
@@ -249,7 +249,10 @@ typedef struct vlc_timer *vlc_timer_t;
 /**
  * Thread handle.
  */
-typedef pthread_t       vlc_thread_t;
+typedef struct
+{
+    pthread_t handle;
+} vlc_thread_t;
 
 /**
  * Return value of a canceled thread.
@@ -660,12 +663,13 @@ void vlc_addr_broadcast(void *addr);
  * The thread must be <i>joined</i> with vlc_join() to reclaim resources
  * when it is not needed anymore.
  *
- * @param th [OUT] pointer to write the handle of the created thread to
- *                 (mandatory, must be non-NULL)
+ * @param th storage space for the handle of the new thread (cannot be NULL)
+ *           [OUT]
  * @param entry entry point for the thread
  * @param data data parameter given to the entry point
  * @param priority thread priority value
  * @return 0 on success, a standard error code on error.
+ * @note In case of error, the value of *th is undefined.
  */
 VLC_API int vlc_clone(vlc_thread_t *th, void *(*entry)(void *), void *data,
                       int priority) VLC_USED;
diff --git a/src/posix/thread.c b/src/posix/thread.c
index f1d9542..ec0fbdb 100644
--- a/src/posix/thread.c
+++ b/src/posix/thread.c
@@ -481,7 +481,7 @@ static int vlc_clone_attr (vlc_thread_t *th, pthread_attr_t *attr,
     assert (ret == 0); /* fails iif VLC_STACKSIZE is invalid */
 #endif
 
-    ret = pthread_create (th, attr, entry, data);
+    ret = pthread_create(&th->handle, attr, entry, data);
     pthread_sigmask (SIG_SETMASK, &oldset, NULL);
     pthread_attr_destroy (attr);
     return ret;
@@ -496,9 +496,9 @@ int vlc_clone (vlc_thread_t *th, void *(*entry) (void *), void *data,
     return vlc_clone_attr (th, &attr, entry, data, priority);
 }
 
-void vlc_join (vlc_thread_t handle, void **result)
+void vlc_join(vlc_thread_t th, void **result)
 {
-    int val = pthread_join (handle, result);
+    int val = pthread_join(th.handle, result);
     VLC_THREAD_ASSERT ("joining thread");
 }
 
@@ -548,7 +548,8 @@ int vlc_clone_detach (vlc_thread_t *th, void *(*entry) (void *), void *data,
 
 vlc_thread_t vlc_thread_self (void)
 {
-    return pthread_self ();
+    vlc_thread_t thread = { pthread_self() };
+    return thread;
 }
 
 #if !defined (__linux__)
@@ -573,7 +574,7 @@ int vlc_set_priority (vlc_thread_t th, int priority)
         else
             sp.sched_priority += sched_get_priority_min (policy = SCHED_RR);
 
-        if (pthread_setschedparam (th, policy, &sp))
+        if (pthread_setschedparam(th.handle, policy, &sp))
             return VLC_EGENERIC;
     }
 #else
@@ -582,9 +583,9 @@ int vlc_set_priority (vlc_thread_t th, int priority)
     return VLC_SUCCESS;
 }
 
-void vlc_cancel (vlc_thread_t thread_id)
+void vlc_cancel(vlc_thread_t th)
 {
-    pthread_cancel (thread_id);
+    pthread_cancel(th.handle);
 }
 
 int vlc_savecancel (void)



More information about the vlc-commits mailing list