diff options
-rw-r--r-- | deadbeef.h | 1 | ||||
-rw-r--r-- | plugins.c | 1 | ||||
-rw-r--r-- | plugins/gtkui/coverart.c | 2 | ||||
-rw-r--r-- | threading.h | 3 | ||||
-rw-r--r-- | threading_pthread.c | 38 |
5 files changed, 44 insertions, 1 deletions
@@ -268,6 +268,7 @@ typedef struct { void (*quit) (void); // threading intptr_t (*thread_start) (void (*fn)(void *ctx), void *ctx); + intptr_t (*thread_start_low_priority) (void (*fn)(void *ctx), void *ctx); int (*thread_join) (intptr_t tid); uintptr_t (*mutex_create) (void); uintptr_t (*mutex_create_nonrecursive) (void); @@ -91,6 +91,7 @@ static DB_functions_t deadbeef_api = { .quit = plug_quit, // threading .thread_start = thread_start, + .thread_start_low_priority = thread_start_low_priority, .thread_join = thread_join, .mutex_create = mutex_create, .mutex_create_nonrecursive = mutex_create_nonrecursive, diff --git a/plugins/gtkui/coverart.c b/plugins/gtkui/coverart.c index 27b2a5af..2cf880ff 100644 --- a/plugins/gtkui/coverart.c +++ b/plugins/gtkui/coverart.c @@ -274,7 +274,7 @@ cover_art_init (void) { terminate = 0; mutex = deadbeef->mutex_create_nonrecursive (); cond = deadbeef->cond_create (); - tid = deadbeef->thread_start (loading_thread, NULL); + tid = deadbeef->thread_start_low_priority (loading_thread, NULL); } void diff --git a/threading.h b/threading.h index f0988574..d543f14c 100644 --- a/threading.h +++ b/threading.h @@ -23,6 +23,9 @@ intptr_t thread_start (void (*fn)(void *ctx), void *ctx); +intptr_t +thread_start_low_priority (void (*fn)(void *ctx), void *ctx); + int thread_join (intptr_t tid); 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; |