src/thread/pthread/SDL_systhread.c
changeset 5506 82a09d5d0f07
parent 5262 b530ef003506
child 5509 5b1b4d820d10
     1.1 --- a/src/thread/pthread/SDL_systhread.c	Fri Mar 25 10:26:25 2011 -0700
     1.2 +++ b/src/thread/pthread/SDL_systhread.c	Fri Mar 25 10:47:49 2011 -0700
     1.3 @@ -91,6 +91,33 @@
     1.4      return ((SDL_threadID) pthread_self());
     1.5  }
     1.6  
     1.7 +int
     1.8 +SDL_SYS_SetThreadPriority(SDL_Thread * thread, SDL_ThreadPriority priority)
     1.9 +{
    1.10 +    struct sched_param sched;
    1.11 +    int policy;
    1.12 +
    1.13 +    if (pthread_getschedparam(thread->handle, &policy, &sched) < 0) {
    1.14 +        SDL_SetError("pthread_getschedparam() failed");
    1.15 +        return -1;
    1.16 +    }
    1.17 +    if (priority == SDL_THREAD_PRIORITY_LOW) {
    1.18 +        sched.sched_priority = sched_get_priority_min(policy);
    1.19 +    } else if (priority == SDL_THREAD_PRIORITY_HIGH) {
    1.20 +        sched.sched_priority = sched_get_priority_max(policy);
    1.21 +    } else {
    1.22 +        int min_priority = sched_get_priority_min(policy);
    1.23 +        int max_priority = sched_get_priority_max(policy);
    1.24 +        int priority = (min_priority + (max_priority - min_priority) / 2);
    1.25 +        sched.sched_priority = priority;
    1.26 +    }
    1.27 +    if (pthread_setschedparam(thread->handle, policy, &sched) < 0) {
    1.28 +        SDL_SetError("pthread_setschedparam() failed");
    1.29 +        return -1;
    1.30 +    }
    1.31 +    return 0;
    1.32 +}
    1.33 +
    1.34  void
    1.35  SDL_SYS_WaitThread(SDL_Thread * thread)
    1.36  {