]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/kern/thread_policy.c
xnu-792.tar.gz
[apple/xnu.git] / osfmk / kern / thread_policy.c
index 2d7e2765c572cc2fdbf0dcda82d7e38f53077247..c9e75fc1ebfa1b2f535aef41f937f6513066d4a4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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>
 
@@ -37,27 +33,24 @@ thread_recompute_priority(
 
 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:
@@ -185,7 +178,7 @@ thread_policy_set(
                break;
        }
 
-       act_unlock_thread(act);
+       thread_mtx_unlock(thread);
 
        return (result);
 }
@@ -241,30 +234,51 @@ thread_task_priority(
        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:
@@ -369,7 +383,7 @@ thread_policy_get(
                break;
        }
 
-       act_unlock_thread(act);
+       thread_mtx_unlock(thread);
 
        return (result);
 }