-#if !CONFIG_EMBEDDED
- error = proc_set1_bgthreadpolicy(curp->task, thread_tid(thread), priority);
- return(error);
-#else /* !CONFIG_EMBEDDED */
- if ( (priority & PRIO_DARWIN_BG) == 0 ) {
- /* turn off backgrounding of thread */
- if ( (ut->uu_flag & UT_BACKGROUND) == 0 ) {
- /* already off */
- return(0);
- }
-
- /*
- * Clear background bit in thread and disable disk IO
- * throttle as well as network traffic management.
- * The corresponding socket flags for sockets created by
- * this thread will be cleared in do_background_socket().
- */
- ut->uu_flag &= ~(UT_BACKGROUND | UT_BACKGROUND_TRAFFIC_MGT);
- ut->uu_iopol_disk = IOPOL_NORMAL;
-
- /* reset thread priority (we did not save previous value) */
- policy.importance = 0;
- thread_policy_set( thread, THREAD_PRECEDENCE_POLICY,
- (thread_policy_t)&policy,
- THREAD_PRECEDENCE_POLICY_COUNT );
- return(0);
- }
-
- /* background this thread */
- if ( (ut->uu_flag & UT_BACKGROUND) != 0 ) {
- /* already backgrounded */
- return(0);
- }
-
- /*
- * Tag thread as background and throttle disk IO, as well
- * as regulate network traffics. Future sockets created
- * by this thread will have their corresponding socket
- * flags set at socket create time.
- */
- ut->uu_flag |= (UT_BACKGROUND | UT_BACKGROUND_TRAFFIC_MGT);
- ut->uu_iopol_disk = IOPOL_THROTTLE;
-
- policy.importance = INT_MIN;
- thread_policy_set( thread, THREAD_PRECEDENCE_POLICY,
- (thread_policy_t)&policy,
- THREAD_PRECEDENCE_POLICY_COUNT );
-
- /* throttle networking IO happens in socket( ) syscall.
- * If UT_{BACKGROUND,BACKGROUND_TRAFFIC_MGT} is set in the current
- * thread then TRAFFIC_MGT_SO_{BACKGROUND,BG_REGULATE} is set.
- * Existing sockets are taken care of by do_background_socket().
- */
-#endif /* !CONFIG_EMBEDDED */
- return(0);
-}
-
-#if CONFIG_EMBEDDED
-int mach_do_background_thread(thread_t thread, int prio);
-
-int
-mach_do_background_thread(thread_t thread, int prio)
-{
- int error = 0;
- struct proc *curp = NULL;
- struct proc *targetp = NULL;
- kauth_cred_t ucred;
-
- targetp = get_bsdtask_info(get_threadtask(thread));
- if (!targetp) {
- return KERN_INVALID_ARGUMENT;