2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
30 * 15 October 2000 (debo)
34 #include <kern/task.h>
40 integer_t max_priority
);
45 task_policy_flavor_t flavor
,
46 task_policy_t policy_info
,
47 mach_msg_type_number_t count
)
49 kern_return_t result
= KERN_SUCCESS
;
51 if (task
== TASK_NULL
|| task
== kernel_task
)
52 return (KERN_INVALID_ARGUMENT
);
56 case TASK_CATEGORY_POLICY
:
58 task_category_policy_t info
= (task_category_policy_t
)policy_info
;
60 if (count
< TASK_CATEGORY_POLICY_COUNT
)
61 return (KERN_INVALID_ARGUMENT
);
65 if ( info
->role
== TASK_FOREGROUND_APPLICATION
||
66 info
->role
== TASK_BACKGROUND_APPLICATION
) {
69 case TASK_FOREGROUND_APPLICATION
:
70 case TASK_BACKGROUND_APPLICATION
:
71 case TASK_UNSPECIFIED
:
73 ((info
->role
== TASK_FOREGROUND_APPLICATION
)?
74 BASEPRI_FOREGROUND
: BASEPRI_BACKGROUND
),
76 task
->role
= info
->role
;
79 case TASK_CONTROL_APPLICATION
:
85 result
= KERN_INVALID_ARGUMENT
;
90 if (info
->role
== TASK_CONTROL_APPLICATION
) {
91 if ( task
!= current_task() ||
92 task
->sec_token
.val
[0] != 0 )
93 result
= KERN_INVALID_ARGUMENT
;
95 task_priority(task
, BASEPRI_CONTROL
, task
->max_priority
);
96 task
->role
= info
->role
;
100 if (info
->role
== TASK_GRAPHICS_SERVER
) {
101 if ( task
!= current_task() ||
102 task
->sec_token
.val
[0] != 0 )
103 result
= KERN_INVALID_ARGUMENT
;
105 task_priority(task
, MAXPRI_SYSTEM
- 3, MAXPRI_SYSTEM
);
106 task
->role
= info
->role
;
110 result
= KERN_INVALID_ARGUMENT
;
118 result
= KERN_INVALID_ARGUMENT
;
129 integer_t max_priority
)
133 task
->max_priority
= max_priority
;
135 if (priority
> task
->max_priority
)
136 priority
= task
->max_priority
;
138 if (priority
< MINPRI
)
141 task
->priority
= priority
;
143 queue_iterate(&task
->thr_acts
, act
, thread_act_t
, thr_acts
) {
144 thread_t thread
= act_lock_thread(act
);
147 thread_task_priority(thread
, priority
, max_priority
);
149 act_unlock_thread(act
);
156 integer_t importance
)
158 if (task
== TASK_NULL
|| task
== kernel_task
)
159 return (KERN_INVALID_ARGUMENT
);
166 return (KERN_TERMINATED
);
169 if (task
->role
>= TASK_CONTROL_APPLICATION
) {
172 return (KERN_INVALID_ARGUMENT
);
175 task_priority(task
, importance
+ BASEPRI_DEFAULT
, task
->max_priority
);
176 task
->role
= TASK_RENICED
;
180 return (KERN_SUCCESS
);
186 task_policy_flavor_t flavor
,
187 task_policy_t policy_info
,
188 mach_msg_type_number_t
*count
,
189 boolean_t
*get_default
)
191 if (task
== TASK_NULL
|| task
== kernel_task
)
192 return (KERN_INVALID_ARGUMENT
);
196 case TASK_CATEGORY_POLICY
:
198 task_category_policy_t info
= (task_category_policy_t
)policy_info
;
200 if (*count
< TASK_CATEGORY_POLICY_COUNT
)
201 return (KERN_INVALID_ARGUMENT
);
204 info
->role
= TASK_UNSPECIFIED
;
207 info
->role
= task
->role
;
214 return (KERN_INVALID_ARGUMENT
);
217 return (KERN_SUCCESS
);