[vlc-commits] Added vlc_set_priority() helper.

Laurent Aimar git at videolan.org
Mon May 23 21:16:29 CEST 2011


vlc | branch: master | Laurent Aimar <fenrir at videolan.org> | Mon May 23 20:29:07 2011 +0200| [2f9948655bdbc005e814903cd40514ac002e211b] | committer: Laurent Aimar

Added vlc_set_priority() helper.

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

 src/libvlc.h       |    2 ++
 src/posix/thread.c |   24 ++++++++++++++++++++++++
 src/win32/thread.c |   10 +++++++++-
 3 files changed, 35 insertions(+), 1 deletions(-)

diff --git a/src/libvlc.h b/src/libvlc.h
index b1d2aea..34c44db 100644
--- a/src/libvlc.h
+++ b/src/libvlc.h
@@ -62,6 +62,8 @@ int vlc_thread_set_priority( vlc_object_t *, int ) VLC_DEPRECATED;
 void vlc_thread_cancel (vlc_object_t *);
 int vlc_object_waitpipe (vlc_object_t *obj);
 
+int vlc_set_priority( vlc_thread_t, int );
+
 void vlc_threads_setup (libvlc_int_t *);
 
 void vlc_trace (const char *fn, const char *file, unsigned line);
diff --git a/src/posix/thread.c b/src/posix/thread.c
index bd22467..67193e4 100644
--- a/src/posix/thread.c
+++ b/src/posix/thread.c
@@ -755,6 +755,30 @@ int vlc_clone_detach (vlc_thread_t *th, void *(*entry) (void *), void *data,
     return vlc_clone_attr (th, &attr, entry, data, priority);
 }
 
+int vlc_set_priority (vlc_thread_t th, int priority)
+{
+#if defined (_POSIX_PRIORITY_SCHEDULING) && (_POSIX_PRIORITY_SCHEDULING >= 0) \
+ && defined (_POSIX_THREAD_PRIORITY_SCHEDULING) \
+ && (_POSIX_THREAD_PRIORITY_SCHEDULING >= 0)
+    if (rt_priorities)
+    {
+        struct sched_param sp = { .sched_priority = priority + rt_offset, };
+        int policy;
+
+        if (sp.sched_priority <= 0)
+            sp.sched_priority += sched_get_priority_max (policy = SCHED_OTHER);
+        else
+            sp.sched_priority += sched_get_priority_min (policy = SCHED_RR);
+
+        if (pthread_setschedparam (th, policy, &sp))
+            return VLC_EGENERIC;
+    }
+#else
+    (void) priority;
+#endif
+    return VLC_SUCCESS;
+}
+
 /**
  * Marks a thread as cancelled. Next time the target thread reaches a
  * cancellation point (while not having disabled cancellation), it will
diff --git a/src/win32/thread.c b/src/win32/thread.c
index 8902050..5ec18d2 100644
--- a/src/win32/thread.c
+++ b/src/win32/thread.c
@@ -634,10 +634,11 @@ static int vlc_clone_attr (vlc_thread_t *p_handle, bool detached,
     if (p_handle != NULL)
         *p_handle = th;
 
-    ResumeThread (hThread);
     if (priority)
         SetThreadPriority (hThread, priority);
 
+    ResumeThread (hThread);
+
     return 0;
 }
 
@@ -673,6 +674,13 @@ int vlc_clone_detach (vlc_thread_t *p_handle, void *(*entry) (void *),
     return vlc_clone_attr (p_handle, true, entry, data, priority);
 }
 
+int vlc_set_priority (vlc_thread_t th, int priority)
+{
+    if (!SetThreadPriority (th->id, priority))
+        return VLC_EGENERIC;
+    return VLC_SUCCESS;
+}
+
 /*** Thread cancellation ***/
 
 /* APC procedure for thread cancellation */



More information about the vlc-commits mailing list