Commit 2f994865 authored by Laurent Aimar's avatar Laurent Aimar

Added vlc_set_priority() helper.

parent a47715a1
...@@ -62,6 +62,8 @@ int vlc_thread_set_priority( vlc_object_t *, int ) VLC_DEPRECATED; ...@@ -62,6 +62,8 @@ int vlc_thread_set_priority( vlc_object_t *, int ) VLC_DEPRECATED;
void vlc_thread_cancel (vlc_object_t *); void vlc_thread_cancel (vlc_object_t *);
int vlc_object_waitpipe (vlc_object_t *obj); 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_threads_setup (libvlc_int_t *);
void vlc_trace (const char *fn, const char *file, unsigned line); void vlc_trace (const char *fn, const char *file, unsigned line);
......
...@@ -755,6 +755,30 @@ int vlc_clone_detach (vlc_thread_t *th, void *(*entry) (void *), void *data, ...@@ -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); 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 * Marks a thread as cancelled. Next time the target thread reaches a
* cancellation point (while not having disabled cancellation), it will * cancellation point (while not having disabled cancellation), it will
......
...@@ -634,10 +634,11 @@ static int vlc_clone_attr (vlc_thread_t *p_handle, bool detached, ...@@ -634,10 +634,11 @@ static int vlc_clone_attr (vlc_thread_t *p_handle, bool detached,
if (p_handle != NULL) if (p_handle != NULL)
*p_handle = th; *p_handle = th;
ResumeThread (hThread);
if (priority) if (priority)
SetThreadPriority (hThread, priority); SetThreadPriority (hThread, priority);
ResumeThread (hThread);
return 0; return 0;
} }
...@@ -673,6 +674,13 @@ int vlc_clone_detach (vlc_thread_t *p_handle, void *(*entry) (void *), ...@@ -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); 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 ***/ /*** Thread cancellation ***/
/* APC procedure for thread cancellation */ /* APC procedure for thread cancellation */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment