Added SDL_THREAD_PRIORITY_TIME_CRITICAL
authorSam Lantinga <slouken@libsdl.org>
Mon, 23 Apr 2018 22:07:56 -0700
changeset 11952d82e6e63c632
parent 11951 28be2719184c
child 11953 3f40e902e8f8
Added SDL_THREAD_PRIORITY_TIME_CRITICAL
include/SDL_thread.h
src/audio/SDL_audio.c
src/thread/psp/SDL_systhread.c
src/thread/pthread/SDL_systhread.c
src/thread/windows/SDL_systhread.c
test/testthread.c
     1.1 --- a/include/SDL_thread.h	Mon Apr 23 21:55:59 2018 -0700
     1.2 +++ b/include/SDL_thread.h	Mon Apr 23 22:07:56 2018 -0700
     1.3 @@ -54,12 +54,13 @@
     1.4  /**
     1.5   *  The SDL thread priority.
     1.6   *
     1.7 - *  \note On many systems you require special privileges to set high priority.
     1.8 + *  \note On many systems you require special privileges to set high or time critical priority.
     1.9   */
    1.10  typedef enum {
    1.11      SDL_THREAD_PRIORITY_LOW,
    1.12      SDL_THREAD_PRIORITY_NORMAL,
    1.13 -    SDL_THREAD_PRIORITY_HIGH
    1.14 +    SDL_THREAD_PRIORITY_HIGH,
    1.15 +    SDL_THREAD_PRIORITY_TIME_CRITICAL
    1.16  } SDL_ThreadPriority;
    1.17  
    1.18  /**
     2.1 --- a/src/audio/SDL_audio.c	Mon Apr 23 21:55:59 2018 -0700
     2.2 +++ b/src/audio/SDL_audio.c	Mon Apr 23 22:07:56 2018 -0700
     2.3 @@ -651,7 +651,7 @@
     2.4      SDL_assert(!device->iscapture);
     2.5  
     2.6      /* The audio mixing is always a high priority thread */
     2.7 -    SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH);
     2.8 +    SDL_SetThreadPriority(SDL_THREAD_PRIORITY_TIME_CRITICAL);
     2.9  
    2.10      /* Perform any thread setup */
    2.11      device->threadid = SDL_ThreadID();
     3.1 --- a/src/thread/psp/SDL_systhread.c	Mon Apr 23 21:55:59 2018 -0700
     3.2 +++ b/src/thread/psp/SDL_systhread.c	Mon Apr 23 22:07:56 2018 -0700
     3.3 @@ -97,6 +97,8 @@
     3.4      if (priority == SDL_THREAD_PRIORITY_LOW) {
     3.5          value = 19;
     3.6      } else if (priority == SDL_THREAD_PRIORITY_HIGH) {
     3.7 +        value = -10;
     3.8 +    } else if (priority == SDL_THREAD_PRIORITY_TIME_CRITICAL) {
     3.9          value = -20;
    3.10      } else {
    3.11          value = 0;
     4.1 --- a/src/thread/pthread/SDL_systhread.c	Mon Apr 23 21:55:59 2018 -0700
     4.2 +++ b/src/thread/pthread/SDL_systhread.c	Mon Apr 23 22:07:56 2018 -0700
     4.3 @@ -275,6 +275,8 @@
     4.4      if (priority == SDL_THREAD_PRIORITY_LOW) {
     4.5          value = 19;
     4.6      } else if (priority == SDL_THREAD_PRIORITY_HIGH) {
     4.7 +        value = -10;
     4.8 +    } else if (priority == SDL_THREAD_PRIORITY_TIME_CRITICAL) {
     4.9          value = -20;
    4.10      } else {
    4.11          value = 0;
    4.12 @@ -290,12 +292,15 @@
    4.13      }
    4.14      if (priority == SDL_THREAD_PRIORITY_LOW) {
    4.15          sched.sched_priority = sched_get_priority_min(policy);
    4.16 -    } else if (priority == SDL_THREAD_PRIORITY_HIGH) {
    4.17 +    } else if (priority == SDL_THREAD_PRIORITY_TIME_CRITICAL) {
    4.18          sched.sched_priority = sched_get_priority_max(policy);
    4.19      } else {
    4.20          int min_priority = sched_get_priority_min(policy);
    4.21          int max_priority = sched_get_priority_max(policy);
    4.22          sched.sched_priority = (min_priority + (max_priority - min_priority) / 2);
    4.23 +        if (priority == SDL_THREAD_PRIORITY_HIGH) {
    4.24 +            sched.sched_priority += (max_priority - min_priority) / 4);
    4.25 +        }
    4.26      }
    4.27      if (pthread_setschedparam(thread, policy, &sched) != 0) {
    4.28          return SDL_SetError("pthread_setschedparam() failed");
     5.1 --- a/src/thread/windows/SDL_systhread.c	Mon Apr 23 21:55:59 2018 -0700
     5.2 +++ b/src/thread/windows/SDL_systhread.c	Mon Apr 23 22:07:56 2018 -0700
     5.3 @@ -231,6 +231,8 @@
     5.4          value = THREAD_PRIORITY_LOWEST;
     5.5      } else if (priority == SDL_THREAD_PRIORITY_HIGH) {
     5.6          value = THREAD_PRIORITY_HIGHEST;
     5.7 +    } else if (priority == SDL_THREAD_PRIORITY_TIME_CRITICAL) {
     5.8 +        value = THREAD_PRIORITY_TIME_CRITICAL;
     5.9      } else {
    5.10          value = THREAD_PRIORITY_NORMAL;
    5.11      }
     6.1 --- a/test/testthread.c	Mon Apr 23 21:55:59 2018 -0700
     6.2 +++ b/test/testthread.c	Mon Apr 23 22:07:56 2018 -0700
     6.3 @@ -38,6 +38,7 @@
     6.4      case SDL_THREAD_PRIORITY_LOW: return "SDL_THREAD_PRIORITY_LOW";
     6.5      case SDL_THREAD_PRIORITY_NORMAL: return "SDL_THREAD_PRIORITY_NORMAL";
     6.6      case SDL_THREAD_PRIORITY_HIGH: return "SDL_THREAD_PRIORITY_HIGH";
     6.7 +    case SDL_THREAD_PRIORITY_TIME_CRITICAL: return "SDL_THREAD_PRIORITY_TIME_CRITICAL";
     6.8      }
     6.9  
    6.10      return "???";
    6.11 @@ -56,7 +57,7 @@
    6.12  
    6.13          if (testprio) {
    6.14              SDL_Log("SDL_SetThreadPriority(%s):%d\n", getprioritystr(prio), SDL_SetThreadPriority(prio));
    6.15 -            if (++prio > SDL_THREAD_PRIORITY_HIGH)
    6.16 +            if (++prio > SDL_THREAD_PRIORITY_TIME_CRITICAL)
    6.17                  prio = SDL_THREAD_PRIORITY_LOW;
    6.18          }
    6.19