2 * Copyright (c) 2000-2004 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 #include <mach/mach_types.h>
24 #include <mach/task_server.h>
26 #include <kern/sched.h>
27 #include <kern/task.h>
33 integer_t max_priority
);
38 task_policy_flavor_t flavor
,
39 task_policy_t policy_info
,
40 mach_msg_type_number_t count
)
42 kern_return_t result
= KERN_SUCCESS
;
44 if (task
== TASK_NULL
|| task
== kernel_task
)
45 return (KERN_INVALID_ARGUMENT
);
49 case TASK_CATEGORY_POLICY
:
51 task_category_policy_t info
= (task_category_policy_t
)policy_info
;
53 if (count
< TASK_CATEGORY_POLICY_COUNT
)
54 return (KERN_INVALID_ARGUMENT
);
58 if ( info
->role
== TASK_FOREGROUND_APPLICATION
||
59 info
->role
== TASK_BACKGROUND_APPLICATION
) {
62 case TASK_FOREGROUND_APPLICATION
:
63 case TASK_BACKGROUND_APPLICATION
:
64 case TASK_UNSPECIFIED
:
66 ((info
->role
== TASK_FOREGROUND_APPLICATION
)?
67 BASEPRI_FOREGROUND
: BASEPRI_BACKGROUND
),
69 task
->role
= info
->role
;
72 case TASK_CONTROL_APPLICATION
:
78 result
= KERN_INVALID_ARGUMENT
;
83 if (info
->role
== TASK_CONTROL_APPLICATION
) {
84 if ( task
!= current_task() ||
85 task
->sec_token
.val
[0] != 0 )
86 result
= KERN_INVALID_ARGUMENT
;
88 task_priority(task
, BASEPRI_CONTROL
, task
->max_priority
);
89 task
->role
= info
->role
;
93 if (info
->role
== TASK_GRAPHICS_SERVER
) {
94 if ( task
!= current_task() ||
95 task
->sec_token
.val
[0] != 0 )
96 result
= KERN_INVALID_ARGUMENT
;
98 task_priority(task
, MAXPRI_RESERVED
- 3, MAXPRI_RESERVED
);
99 task
->role
= info
->role
;
103 result
= KERN_INVALID_ARGUMENT
;
111 result
= KERN_INVALID_ARGUMENT
;
122 integer_t max_priority
)
126 task
->max_priority
= max_priority
;
128 if (priority
> task
->max_priority
)
129 priority
= task
->max_priority
;
131 if (priority
< MINPRI
)
134 task
->priority
= priority
;
136 queue_iterate(&task
->threads
, thread
, thread_t
, task_threads
) {
137 thread_mtx_lock(thread
);
140 thread_task_priority(thread
, priority
, max_priority
);
142 thread_mtx_unlock(thread
);
149 integer_t importance
)
151 if (task
== TASK_NULL
|| task
== kernel_task
)
152 return (KERN_INVALID_ARGUMENT
);
159 return (KERN_TERMINATED
);
162 if (task
->role
>= TASK_CONTROL_APPLICATION
) {
165 return (KERN_INVALID_ARGUMENT
);
168 task_priority(task
, importance
+ BASEPRI_DEFAULT
, task
->max_priority
);
169 task
->role
= TASK_RENICED
;
173 return (KERN_SUCCESS
);
179 task_policy_flavor_t flavor
,
180 task_policy_t policy_info
,
181 mach_msg_type_number_t
*count
,
182 boolean_t
*get_default
)
184 if (task
== TASK_NULL
|| task
== kernel_task
)
185 return (KERN_INVALID_ARGUMENT
);
189 case TASK_CATEGORY_POLICY
:
191 task_category_policy_t info
= (task_category_policy_t
)policy_info
;
193 if (*count
< TASK_CATEGORY_POLICY_COUNT
)
194 return (KERN_INVALID_ARGUMENT
);
197 info
->role
= TASK_UNSPECIFIED
;
200 info
->role
= task
->role
;
207 return (KERN_INVALID_ARGUMENT
);
210 return (KERN_SUCCESS
);