summaryrefslogtreecommitdiff
path: root/threading_pthread.c
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-03-14 13:06:43 +0100
committerGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-03-14 13:06:43 +0100
commit164210c796f2df48d4a3304e9d38e32a07c5fca0 (patch)
tree36d3fd4e2ecbc9a4845ba729f55aadc401118c2f /threading_pthread.c
parent1320a7469243071d6cc51c6c594a0373845bbe7e (diff)
start coverart loading thread with low priority
Diffstat (limited to 'threading_pthread.c')
-rw-r--r--threading_pthread.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/threading_pthread.c b/threading_pthread.c
index 96e464b6..4f7cba1a 100644
--- a/threading_pthread.c
+++ b/threading_pthread.c
@@ -46,6 +46,44 @@ thread_start (void (*fn)(void *ctx), void *ctx) {
return tid;
}
+intptr_t
+thread_start_low_priority (void (*fn)(void *ctx), void *ctx) {
+ pthread_t tid;
+ pthread_attr_t attr;
+ int s = pthread_attr_init (&attr);
+ if (s != 0) {
+ fprintf (stderr, "pthread_attr_init failed: %s\n", strerror (s));
+ return 0;
+ }
+ int policy;
+ s = pthread_attr_getschedpolicy (&attr, &policy);
+ if (s != 0) {
+ fprintf (stderr, "pthread_attr_getschedpolicy failed: %s\n", strerror (s));
+ return 0;
+ }
+ int minprio = sched_get_priority_min (policy);
+
+ s = pthread_create (&tid, &attr, (void *(*)(void *))fn, (void*)ctx);
+ if (s != 0) {
+ fprintf (stderr, "pthread_create failed: %s\n", strerror (s));
+ return 0;
+ }
+ s = pthread_setschedprio (tid, minprio);
+ if (s != 0) {
+ fprintf (stderr, "pthread_setschedprio failed: %s\n", strerror (s));
+ pthread_cancel (tid);
+ return 0;
+ }
+
+ s = pthread_attr_destroy (&attr);
+ if (s != 0) {
+ fprintf (stderr, "pthread_attr_destroy failed: %s\n", strerror (s));
+ pthread_cancel (tid);
+ return 0;
+ }
+ return tid;
+}
+
int
thread_join (intptr_t tid) {
void *retval;