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
:
70 ((info
->role
== TASK_FOREGROUND_APPLICATION
)?
71 BASEPRI_FOREGROUND
: BASEPRI_BACKGROUND
),
73 task
->role
= info
->role
;
76 case TASK_CONTROL_APPLICATION
:
82 result
= KERN_INVALID_ARGUMENT
;
87 if (info
->role
== TASK_CONTROL_APPLICATION
) {
88 if ( task
!= current_task() ||
89 task
->sec_token
.val
[0] != 0 )
90 result
= KERN_INVALID_ARGUMENT
;
92 task_priority(task
, BASEPRI_CONTROL
, task
->max_priority
);
93 task
->role
= info
->role
;
97 if (info
->role
== TASK_GRAPHICS_SERVER
) {
98 if ( task
!= current_task() ||
99 task
->sec_token
.val
[0] != 0 )
100 result
= KERN_INVALID_ARGUMENT
;
102 task_priority(task
, MAXPRI_SYSTEM
- 3, MAXPRI_SYSTEM
);
103 task
->role
= info
->role
;
107 result
= KERN_INVALID_ARGUMENT
;
115 result
= KERN_INVALID_ARGUMENT
;
126 integer_t max_priority
)
130 task
->max_priority
= max_priority
;
132 if (priority
> task
->max_priority
)
133 priority
= task
->max_priority
;
135 if (priority
< MINPRI
)
138 task
->priority
= priority
;
140 queue_iterate(&task
->threads
, act
, thread_act_t
, task_threads
) {
141 thread_t thread
= act_lock_thread(act
);
144 thread_task_priority(thread
, priority
, max_priority
);
146 act_unlock_thread(act
);
153 integer_t importance
)
155 if (task
== TASK_NULL
|| task
== kernel_task
)
156 return (KERN_INVALID_ARGUMENT
);
163 return (KERN_TERMINATED
);
166 if (task
->role
>= TASK_CONTROL_APPLICATION
) {
169 return (KERN_INVALID_ARGUMENT
);
172 task_priority(task
, importance
+ BASEPRI_DEFAULT
, task
->max_priority
);
173 task
->role
= TASK_RENICED
;
177 return (KERN_SUCCESS
);
183 task_policy_flavor_t flavor
,
184 task_policy_t policy_info
,
185 mach_msg_type_number_t
*count
,
186 boolean_t
*get_default
)
188 if (task
== TASK_NULL
|| task
== kernel_task
)
189 return (KERN_INVALID_ARGUMENT
);
193 case TASK_CATEGORY_POLICY
:
195 task_category_policy_t info
= (task_category_policy_t
)policy_info
;
197 if (*count
< TASK_CATEGORY_POLICY_COUNT
)
198 return (KERN_INVALID_ARGUMENT
);
201 info
->role
= TASK_UNSPECIFIED
;
204 info
->role
= task
->role
;
211 return (KERN_INVALID_ARGUMENT
);
214 return (KERN_SUCCESS
);