2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
27 * 15 October 2000 (debo)
31 #include <kern/task.h>
37 integer_t max_priority
);
42 task_policy_flavor_t flavor
,
43 task_policy_t policy_info
,
44 mach_msg_type_number_t count
)
46 kern_return_t result
= KERN_SUCCESS
;
48 if (task
== TASK_NULL
|| task
== kernel_task
)
49 return (KERN_INVALID_ARGUMENT
);
53 case TASK_CATEGORY_POLICY
:
55 task_category_policy_t info
= (task_category_policy_t
)policy_info
;
57 if (count
< TASK_CATEGORY_POLICY_COUNT
)
58 return (KERN_INVALID_ARGUMENT
);
62 if ( info
->role
== TASK_FOREGROUND_APPLICATION
||
63 info
->role
== TASK_BACKGROUND_APPLICATION
) {
66 case TASK_FOREGROUND_APPLICATION
:
67 case TASK_BACKGROUND_APPLICATION
:
68 case TASK_UNSPECIFIED
:
69 task_priority(task
, BASEPRI_DEFAULT
+
70 ((info
->role
== TASK_FOREGROUND_APPLICATION
)? +16: +15),
72 task
->role
= info
->role
;
75 case TASK_CONTROL_APPLICATION
:
81 result
= KERN_INVALID_ARGUMENT
;
86 if (info
->role
== TASK_CONTROL_APPLICATION
) {
87 if ( task
!= current_task() ||
88 task
->sec_token
.val
[0] != 0 )
89 result
= KERN_INVALID_ARGUMENT
;
91 task_priority(task
, BASEPRI_DEFAULT
+ 17, task
->max_priority
);
92 task
->role
= info
->role
;
96 if (info
->role
== TASK_GRAPHICS_SERVER
) {
97 if ( task
!= current_task() ||
98 task
->sec_token
.val
[0] != 0 )
99 result
= KERN_INVALID_ARGUMENT
;
101 task_priority(task
, MAXPRI_SYSTEM
- 3, MAXPRI_SYSTEM
);
102 task
->role
= info
->role
;
106 result
= KERN_INVALID_ARGUMENT
;
114 result
= KERN_INVALID_ARGUMENT
;
125 integer_t max_priority
)
129 task
->max_priority
= max_priority
;
131 if (priority
> task
->max_priority
)
132 priority
= task
->max_priority
;
134 if (priority
< MINPRI
)
137 task
->priority
= priority
;
139 queue_iterate(&task
->thr_acts
, act
, thread_act_t
, thr_acts
) {
140 thread_t thread
= act_lock_thread(act
);
143 thread_task_priority(thread
, priority
, max_priority
);
145 act_unlock_thread(act
);
152 integer_t importance
)
154 if (task
== TASK_NULL
|| task
== kernel_task
)
155 return (KERN_INVALID_ARGUMENT
);
162 return (KERN_TERMINATED
);
165 if (task
->role
>= TASK_CONTROL_APPLICATION
) {
168 return (KERN_INVALID_ARGUMENT
);
171 task_priority(task
, importance
+ BASEPRI_DEFAULT
, task
->max_priority
);
172 task
->role
= TASK_RENICED
;
176 return (KERN_SUCCESS
);
182 task_policy_flavor_t flavor
,
183 task_policy_t policy_info
,
184 mach_msg_type_number_t
*count
,
185 boolean_t
*get_default
)
187 if (task
== TASK_NULL
|| task
== kernel_task
)
188 return (KERN_INVALID_ARGUMENT
);
192 case TASK_CATEGORY_POLICY
:
194 task_category_policy_t info
= (task_category_policy_t
)policy_info
;
196 if (*count
< TASK_CATEGORY_POLICY_COUNT
)
197 return (KERN_INVALID_ARGUMENT
);
200 info
->role
= TASK_UNSPECIFIED
;
203 info
->role
= task
->role
;
210 return (KERN_INVALID_ARGUMENT
);
213 return (KERN_SUCCESS
);