src/thread/pthread/SDL_systhread.c
changeset 5509 5b1b4d820d10
parent 5506 82a09d5d0f07
child 5510 55519e27e5d1
     1.1 --- a/src/thread/pthread/SDL_systhread.c	Fri Mar 25 11:09:57 2011 -0700
     1.2 +++ b/src/thread/pthread/SDL_systhread.c	Fri Mar 25 12:44:06 2011 -0700
     1.3 @@ -23,6 +23,11 @@
     1.4  
     1.5  #include <pthread.h>
     1.6  #include <signal.h>
     1.7 +#ifdef linux
     1.8 +#include <sys/time.h>
     1.9 +#include <sys/resource.h>
    1.10 +#include <sys/syscall.h>
    1.11 +#endif
    1.12  
    1.13  #include "SDL_thread.h"
    1.14  #include "../SDL_thread_c.h"
    1.15 @@ -34,6 +39,7 @@
    1.16      SIGVTALRM, SIGPROF, 0
    1.17  };
    1.18  
    1.19 +
    1.20  static void *
    1.21  RunThread(void *data)
    1.22  {
    1.23 @@ -92,12 +98,29 @@
    1.24  }
    1.25  
    1.26  int
    1.27 -SDL_SYS_SetThreadPriority(SDL_Thread * thread, SDL_ThreadPriority priority)
    1.28 +SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
    1.29  {
    1.30 +#ifdef linux
    1.31 +    int value;
    1.32 +
    1.33 +    if (priority == SDL_THREAD_PRIORITY_LOW) {
    1.34 +        value = 19;
    1.35 +    } else if (priority == SDL_THREAD_PRIORITY_HIGH) {
    1.36 +        value = -20;
    1.37 +    } else {
    1.38 +        value = 0;
    1.39 +    }
    1.40 +    if (setpriority(PRIO_PROCESS, syscall(SYS_gettid), value) < 0) {
    1.41 +        SDL_SetError("setpriority() failed");
    1.42 +        return -1;
    1.43 +    }
    1.44 +    return 0;
    1.45 +#else
    1.46      struct sched_param sched;
    1.47      int policy;
    1.48 +    pthread_t thread = pthread_self();
    1.49  
    1.50 -    if (pthread_getschedparam(thread->handle, &policy, &sched) < 0) {
    1.51 +    if (pthread_getschedparam(thread, &policy, &sched) < 0) {
    1.52          SDL_SetError("pthread_getschedparam() failed");
    1.53          return -1;
    1.54      }
    1.55 @@ -108,14 +131,14 @@
    1.56      } else {
    1.57          int min_priority = sched_get_priority_min(policy);
    1.58          int max_priority = sched_get_priority_max(policy);
    1.59 -        int priority = (min_priority + (max_priority - min_priority) / 2);
    1.60 -        sched.sched_priority = priority;
    1.61 +        sched.sched_priority = (min_priority + (max_priority - min_priority) / 2);
    1.62      }
    1.63 -    if (pthread_setschedparam(thread->handle, policy, &sched) < 0) {
    1.64 +    if (pthread_setschedparam(thread, policy, &sched) < 0) {
    1.65          SDL_SetError("pthread_setschedparam() failed");
    1.66          return -1;
    1.67      }
    1.68      return 0;
    1.69 +#endif /* linux */
    1.70  }
    1.71  
    1.72  void