From 164210c796f2df48d4a3304e9d38e32a07c5fca0 Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Sun, 14 Mar 2010 13:06:43 +0100 Subject: start coverart loading thread with low priority --- threading_pthread.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'threading_pthread.c') 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; -- cgit v1.2.3