1 /*
2 * sched_get_priority_min.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: rpj@callisto.canberra.edu.au
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
37 #include "pthread.h"
38 #include "implement.h"
39 #include "sched.h"
40
41 /*
42 * On Windows98, THREAD_PRIORITY_LOWEST is (-2) and
43 * THREAD_PRIORITY_HIGHEST is 2, and everything works just fine.
44 *
45 * On WinCE 3.0, it so happen that THREAD_PRIORITY_LOWEST is 5
46 * and THREAD_PRIORITY_HIGHEST is 1 (yes, I know, it is funny:
47 * highest priority use smaller numbers) and the following happens:
48 *
49 * sched_get_priority_min() returns 5
50 * sched_get_priority_max() returns 1
51 *
52 * The following table shows the base priority levels for combinations
53 * of priority class and priority value in Win32.
54 *
55 * Process Priority Class Thread Priority Level
56 * -----------------------------------------------------------------
57 * 1 IDLE_PRIORITY_CLASS THREAD_PRIORITY_IDLE
58 * 1 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_IDLE
59 * 1 NORMAL_PRIORITY_CLASS THREAD_PRIORITY_IDLE
60 * 1 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_IDLE
61 * 1 HIGH_PRIORITY_CLASS THREAD_PRIORITY_IDLE
62 * 2 IDLE_PRIORITY_CLASS THREAD_PRIORITY_LOWEST
63 * 3 IDLE_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL
64 * 4 IDLE_PRIORITY_CLASS THREAD_PRIORITY_NORMAL
65 * 4 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_LOWEST
66 * 5 IDLE_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL
67 * 5 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL
68 * 5 Background NORMAL_PRIORITY_CLASS THREAD_PRIORITY_LOWEST
69 * 6 IDLE_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST
70 * 6 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_NORMAL
71 * 6 Background NORMAL_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL
72 * 7 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL
73 * 7 Background NORMAL_PRIORITY_CLASS THREAD_PRIORITY_NORMAL
74 * 7 Foreground NORMAL_PRIORITY_CLASS THREAD_PRIORITY_LOWEST
75 * 8 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST
76 * 8 NORMAL_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL
77 * 8 Foreground NORMAL_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL
78 * 8 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_LOWEST
79 * 9 NORMAL_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST
80 * 9 Foreground NORMAL_PRIORITY_CLASS THREAD_PRIORITY_NORMAL
81 * 9 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL
82 * 10 Foreground NORMAL_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL
83 * 10 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_NORMAL
84 * 11 Foreground NORMAL_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST
85 * 11 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL
86 * 11 HIGH_PRIORITY_CLASS THREAD_PRIORITY_LOWEST
87 * 12 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST
88 * 12 HIGH_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL
89 * 13 HIGH_PRIORITY_CLASS THREAD_PRIORITY_NORMAL
90 * 14 HIGH_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL
91 * 15 HIGH_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST
92 * 15 HIGH_PRIORITY_CLASS THREAD_PRIORITY_TIME_CRITICAL
93 * 15 IDLE_PRIORITY_CLASS THREAD_PRIORITY_TIME_CRITICAL
94 * 15 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_TIME_CRITICAL
95 * 15 NORMAL_PRIORITY_CLASS THREAD_PRIORITY_TIME_CRITICAL
96 * 15 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_TIME_CRITICAL
97 * 16 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_IDLE
98 * 17 REALTIME_PRIORITY_CLASS -7
99 * 18 REALTIME_PRIORITY_CLASS -6
100 * 19 REALTIME_PRIORITY_CLASS -5
101 * 20 REALTIME_PRIORITY_CLASS -4
102 * 21 REALTIME_PRIORITY_CLASS -3
103 * 22 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_LOWEST
104 * 23 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL
105 * 24 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_NORMAL
106 * 25 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL
107 * 26 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST
108 * 27 REALTIME_PRIORITY_CLASS 3
109 * 28 REALTIME_PRIORITY_CLASS 4
110 * 29 REALTIME_PRIORITY_CLASS 5
111 * 30 REALTIME_PRIORITY_CLASS 6
112 * 31 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_TIME_CRITICAL
113 *
114 * Windows NT: Values -7, -6, -5, -4, -3, 3, 4, 5, and 6 are not supported.
115 *
116 */
117
118
119 int
sched_get_priority_min(int policy)120 sched_get_priority_min (int policy)
121 {
122 if (policy < SCHED_MIN || policy > SCHED_MAX)
123 {
124 errno = EINVAL;
125 return -1;
126 }
127
128 #if (THREAD_PRIORITY_LOWEST > THREAD_PRIORITY_NORMAL)
129 /* WinCE? */
130 return PTW32_MIN (THREAD_PRIORITY_IDLE, THREAD_PRIORITY_TIME_CRITICAL);
131 #else
132 /* This is independent of scheduling policy in Win32. */
133 return PTW32_MIN (THREAD_PRIORITY_IDLE, THREAD_PRIORITY_TIME_CRITICAL);
134 #endif
135 }
136