/*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
*
* @APPLE_LICENSE_HEADER_END@
*/
-/*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
- *
- * HISTORY
- *
- * 15 October 2000 (debo)
- * Created.
- */
+#include <mach/mach_types.h>
+#include <mach/thread_act_server.h>
+
+#include <kern/kern_types.h>
+#include <kern/processor.h>
#include <kern/thread.h>
static void
kern_return_t
thread_policy_set(
- thread_act_t act,
+ thread_t thread,
thread_policy_flavor_t flavor,
thread_policy_t policy_info,
mach_msg_type_number_t count)
{
kern_return_t result = KERN_SUCCESS;
- thread_t thread;
spl_t s;
- if (act == THR_ACT_NULL)
+ if (thread == THREAD_NULL)
return (KERN_INVALID_ARGUMENT);
- thread = act_lock_thread(act);
- if (!act->active) {
- act_unlock_thread(act);
+ thread_mtx_lock(thread);
+ if (!thread->active) {
+ thread_mtx_unlock(thread);
return (KERN_TERMINATED);
}
- assert(thread != THREAD_NULL);
-
switch (flavor) {
case THREAD_EXTENDED_POLICY:
thread_lock(thread);
if (!(thread->sched_mode & TH_MODE_FAILSAFE)) {
+ integer_t oldmode = (thread->sched_mode & TH_MODE_TIMESHARE);
+
thread->sched_mode &= ~TH_MODE_REALTIME;
- if (timeshare)
+ if (timeshare && !oldmode) {
thread->sched_mode |= TH_MODE_TIMESHARE;
+
+ if (thread->state & TH_RUN)
+ pset_share_incr(thread->processor_set);
+ }
else
+ if (!timeshare && oldmode) {
thread->sched_mode &= ~TH_MODE_TIMESHARE;
+ if (thread->state & TH_RUN)
+ pset_share_decr(thread->processor_set);
+ }
+
thread_recompute_priority(thread);
}
else {
}
info = (thread_time_constraint_policy_t)policy_info;
- if ( info->computation > max_rt_quantum ||
+ if ( info->constraint < info->computation ||
+ info->computation > max_rt_quantum ||
info->computation < min_rt_quantum ) {
result = KERN_INVALID_ARGUMENT;
break;
thread->realtime.preemptible = info->preemptible;
if (!(thread->sched_mode & TH_MODE_FAILSAFE)) {
- thread->sched_mode &= ~TH_MODE_TIMESHARE;
+ if (thread->sched_mode & TH_MODE_TIMESHARE) {
+ thread->sched_mode &= ~TH_MODE_TIMESHARE;
+
+ if (thread->state & TH_RUN)
+ pset_share_decr(thread->processor_set);
+ }
thread->sched_mode |= TH_MODE_REALTIME;
thread_recompute_priority(thread);
}
break;
}
- act_unlock_thread(act);
+ thread_mtx_unlock(thread);
return (result);
}
integer_t priority;
if (thread->sched_mode & TH_MODE_REALTIME)
- priority = BASEPRI_REALTIME;
+ priority = BASEPRI_RTQUEUES;
else {
if (thread->importance > MAXPRI)
priority = MAXPRI;
priority = MINPRI;
}
- if (thread->depress_priority >= 0)
- thread->depress_priority = priority;
- else {
- thread->priority = priority;
- compute_priority(thread, TRUE);
-
- if (thread == current_thread())
- ast_on(AST_BLOCK);
- }
+ set_priority(thread, priority);
}
void
splx(s);
}
+void
+thread_policy_reset(
+ thread_t thread)
+{
+ if (!(thread->sched_mode & TH_MODE_FAILSAFE)) {
+ thread->sched_mode &= ~TH_MODE_REALTIME;
+
+ if (!(thread->sched_mode & TH_MODE_TIMESHARE)) {
+ thread->sched_mode |= TH_MODE_TIMESHARE;
+
+ if (thread->state & TH_RUN)
+ pset_share_incr(thread->processor_set);
+ }
+ }
+ else {
+ thread->safe_mode = 0;
+ thread->sched_mode &= ~TH_MODE_FAILSAFE;
+ }
+
+ thread->importance = 0;
+
+ thread_recompute_priority(thread);
+}
+
kern_return_t
thread_policy_get(
- thread_act_t act,
+ thread_t thread,
thread_policy_flavor_t flavor,
thread_policy_t policy_info,
mach_msg_type_number_t *count,
boolean_t *get_default)
{
kern_return_t result = KERN_SUCCESS;
- thread_t thread;
spl_t s;
- if (act == THR_ACT_NULL)
+ if (thread == THREAD_NULL)
return (KERN_INVALID_ARGUMENT);
- thread = act_lock_thread(act);
- if (!act->active) {
- act_unlock_thread(act);
+ thread_mtx_lock(thread);
+ if (!thread->active) {
+ thread_mtx_unlock(thread);
return (KERN_TERMINATED);
}
- assert(thread != THREAD_NULL);
-
switch (flavor) {
case THREAD_EXTENDED_POLICY:
break;
}
- act_unlock_thread(act);
+ thread_mtx_unlock(thread);
return (result);
}