sched_get_priority_max.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * sched_get_priority_max.c
  3. *
  4. * Description:
  5. * POSIX thread functions that deal with thread scheduling.
  6. *
  7. * --------------------------------------------------------------------------
  8. *
  9. * Pthreads-win32 - POSIX Threads Library for Win32
  10. * Copyright(C) 1998 John E. Bossom
  11. * Copyright(C) 1999,2005 Pthreads-win32 contributors
  12. *
  13. * Contact Email: [email protected]
  14. *
  15. * The current list of contributors is contained
  16. * in the file CONTRIBUTORS included with the source
  17. * code distribution. The list can also be seen at the
  18. * following World Wide Web location:
  19. * http://sources.redhat.com/pthreads-win32/contributors.html
  20. *
  21. * This library is free software; you can redistribute it and/or
  22. * modify it under the terms of the GNU Lesser General Public
  23. * License as published by the Free Software Foundation; either
  24. * version 2 of the License, or (at your option) any later version.
  25. *
  26. * This library is distributed in the hope that it will be useful,
  27. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  29. * Lesser General Public License for more details.
  30. *
  31. * You should have received a copy of the GNU Lesser General Public
  32. * License along with this library in the file COPYING.LIB;
  33. * if not, write to the Free Software Foundation, Inc.,
  34. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  35. */
  36. #include "pthread.h"
  37. #include "implement.h"
  38. #include "sched.h"
  39. /*
  40. * On Windows98, THREAD_PRIORITY_LOWEST is (-2) and
  41. * THREAD_PRIORITY_HIGHEST is 2, and everything works just fine.
  42. *
  43. * On WinCE 3.0, it so happen that THREAD_PRIORITY_LOWEST is 5
  44. * and THREAD_PRIORITY_HIGHEST is 1 (yes, I know, it is funny:
  45. * highest priority use smaller numbers) and the following happens:
  46. *
  47. * sched_get_priority_min() returns 5
  48. * sched_get_priority_max() returns 1
  49. *
  50. * The following table shows the base priority levels for combinations
  51. * of priority class and priority value in Win32.
  52. *
  53. * Process Priority Class Thread Priority Level
  54. * -----------------------------------------------------------------
  55. * 1 IDLE_PRIORITY_CLASS THREAD_PRIORITY_IDLE
  56. * 1 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_IDLE
  57. * 1 NORMAL_PRIORITY_CLASS THREAD_PRIORITY_IDLE
  58. * 1 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_IDLE
  59. * 1 HIGH_PRIORITY_CLASS THREAD_PRIORITY_IDLE
  60. * 2 IDLE_PRIORITY_CLASS THREAD_PRIORITY_LOWEST
  61. * 3 IDLE_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL
  62. * 4 IDLE_PRIORITY_CLASS THREAD_PRIORITY_NORMAL
  63. * 4 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_LOWEST
  64. * 5 IDLE_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL
  65. * 5 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL
  66. * 5 Background NORMAL_PRIORITY_CLASS THREAD_PRIORITY_LOWEST
  67. * 6 IDLE_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST
  68. * 6 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_NORMAL
  69. * 6 Background NORMAL_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL
  70. * 7 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL
  71. * 7 Background NORMAL_PRIORITY_CLASS THREAD_PRIORITY_NORMAL
  72. * 7 Foreground NORMAL_PRIORITY_CLASS THREAD_PRIORITY_LOWEST
  73. * 8 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST
  74. * 8 NORMAL_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL
  75. * 8 Foreground NORMAL_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL
  76. * 8 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_LOWEST
  77. * 9 NORMAL_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST
  78. * 9 Foreground NORMAL_PRIORITY_CLASS THREAD_PRIORITY_NORMAL
  79. * 9 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL
  80. * 10 Foreground NORMAL_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL
  81. * 10 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_NORMAL
  82. * 11 Foreground NORMAL_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST
  83. * 11 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL
  84. * 11 HIGH_PRIORITY_CLASS THREAD_PRIORITY_LOWEST
  85. * 12 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST
  86. * 12 HIGH_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL
  87. * 13 HIGH_PRIORITY_CLASS THREAD_PRIORITY_NORMAL
  88. * 14 HIGH_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL
  89. * 15 HIGH_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST
  90. * 15 HIGH_PRIORITY_CLASS THREAD_PRIORITY_TIME_CRITICAL
  91. * 15 IDLE_PRIORITY_CLASS THREAD_PRIORITY_TIME_CRITICAL
  92. * 15 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_TIME_CRITICAL
  93. * 15 NORMAL_PRIORITY_CLASS THREAD_PRIORITY_TIME_CRITICAL
  94. * 15 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_TIME_CRITICAL
  95. * 16 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_IDLE
  96. * 17 REALTIME_PRIORITY_CLASS -7
  97. * 18 REALTIME_PRIORITY_CLASS -6
  98. * 19 REALTIME_PRIORITY_CLASS -5
  99. * 20 REALTIME_PRIORITY_CLASS -4
  100. * 21 REALTIME_PRIORITY_CLASS -3
  101. * 22 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_LOWEST
  102. * 23 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL
  103. * 24 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_NORMAL
  104. * 25 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL
  105. * 26 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST
  106. * 27 REALTIME_PRIORITY_CLASS 3
  107. * 28 REALTIME_PRIORITY_CLASS 4
  108. * 29 REALTIME_PRIORITY_CLASS 5
  109. * 30 REALTIME_PRIORITY_CLASS 6
  110. * 31 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_TIME_CRITICAL
  111. *
  112. * Windows NT: Values -7, -6, -5, -4, -3, 3, 4, 5, and 6 are not supported.
  113. */
  114. int
  115. sched_get_priority_max (int policy)
  116. {
  117. if (policy < SCHED_MIN || policy > SCHED_MAX)
  118. {
  119. errno = EINVAL;
  120. return -1;
  121. }
  122. #if (THREAD_PRIORITY_LOWEST > THREAD_PRIORITY_NORMAL)
  123. /* WinCE? */
  124. return PTW32_MAX (THREAD_PRIORITY_IDLE, THREAD_PRIORITY_TIME_CRITICAL);
  125. #else
  126. /* This is independent of scheduling policy in Win32. */
  127. return PTW32_MAX (THREAD_PRIORITY_IDLE, THREAD_PRIORITY_TIME_CRITICAL);
  128. #endif
  129. }