VirtualBox

Ignore:
Timestamp:
Jan 27, 2007 7:25:25 PM (18 years ago)
Author:
vboxsync
Message:

early commit.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r0drv/darwin/process-r0drv-darwin.cpp

    r375 r384  
    11/* $Id$ */
    22/** @file
    3  * InnoTek Portable Runtime - Threads, Ring-0 Driver, Darwin.
     3 * InnoTek Portable Runtime - Process, Ring-0 Driver, Darwin.
    44 */
    55
     
    2424*******************************************************************************/
    2525#include "the-darwin-kernel.h"
    26 #include <iprt/thread.h>
    27 #include <iprt/err.h>
    28 #include <iprt/assert.h>
    29 #include "internal/thread.h"
     26#include <iprt/process.h>
    3027
    3128
    32 RTDECL(RTTHREAD) RTThreadSelf(void)
     29RTDECL(RTPROCESS) RTProcSelf(void)
    3330{
    34     return (RTTHREAD)current_thread();
     31    return proc_selfpid();
    3532}
    3633
    3734
    38 RTDECL(int)   RTThreadSleep(unsigned cMillies)
     35RTR0DECL(RTR0PROCESS) RTR0ProcHandleSelf(void)
    3936{
    40     uint64_t u64Deadline;
    41     clock_interval_to_deadline(cMillies, kMillisecondScale, &u64Deadline);
    42     clock_delay_until(u64Deadline);
    43     return VINF_SUCCESS;
     37    return (RTR0PROCESS)current_task();
    4438}
    4539
    46 
    47 RTDECL(bool) RTThreadYield(void)
    48 {
    49     thread_block(THREAD_CONTINUE_NULL);
    50     return true; /* this is fishy */
    51 }
    52 
    53 
    54 int rtThreadNativeSetPriority(RTTHREAD Thread, RTTHREADTYPE enmType)
    55 {
    56     /*
    57      * Convert the priority type to scheduling policies.
    58      */
    59     bool                            fSetExtended = false;
    60     thread_extended_policy          Extended = { true };
    61     bool                            fSetTimeContstraint = false;
    62     thread_time_constraint_policy   TimeConstraint = { 0, 0, 0, true };
    63     thread_precedence_policy        Precedence = { 0 };
    64     switch (enmType)
    65     {
    66         case RTTHREADTYPE_INFREQUENT_POLLER:
    67             Precedence.importance = 1;
    68             break;
    69 
    70         case RTTHREADTYPE_EMULATION:
    71             Precedence.importance = 30;
    72             break;
    73 
    74         case RTTHREADTYPE_DEFAULT:
    75             Precedence.importance = 31;
    76             break;
    77 
    78         case RTTHREADTYPE_MSG_PUMP:
    79             Precedence.importance = 34;
    80             break;
    81 
    82         case RTTHREADTYPE_IO:
    83             Precedence.importance = 98;
    84             break;
    85 
    86         case RTTHREADTYPE_TIMER:
    87             Precedence.importance = 0x7fffffff;
    88 
    89             fSetExtended = true;
    90             Extended.timeshare = FALSE;
    91 
    92             fSetTimeContstraint = true;
    93             TimeConstraint.period = 0; /* not really true for a real timer thread, but we've really no idea. */
    94             TimeConstraint.computation = rtDarwinAbsTimeFromNano(100000); /* 100 us*/
    95             TimeConstraint.constraint = rtDarwinAbsTimeFromNano(500000);  /* 500 us */
    96             TimeConstraint.preemptible = FALSE;
    97             break;
    98 
    99         default:
    100             AssertMsgFailed(("enmType=%d\n", enmType));
    101             return VERR_INVALID_PARAMETER;
    102     }
    103 
    104     /*
    105      * Do the actual modification.
    106      */
    107     kern_return_t rc = thread_policy_set((thread_t)Thread, THREAD_PRECEDENCE_POLICY,
    108                                          (thread_policy_t)&Precedence, THREAD_PRECEDENCE_POLICY_COUNT);
    109     AssertMsg(rc == KERN_SUCCESS, ("%rc\n", rc)); NOREF(rc);
    110 
    111     if (fSetExtended)
    112     {
    113         rc = thread_policy_set((thread_t)Thread, THREAD_EXTENDED_POLICY,
    114                                (thread_policy_t)&Extended, THREAD_EXTENDED_POLICY_COUNT);
    115         AssertMsg(rc == KERN_SUCCESS, ("%rc\n", rc));
    116     }
    117 
    118     if (fSetTimeContstraint)
    119     {
    120         rc = thread_policy_set((thread_t)Thread, THREAD_TIME_CONSTRAINT_POLICY,
    121                                (thread_policy_t)&TimeConstraint, THREAD_TIME_CONSTRAINT_POLICY_COUNT);
    122         AssertMsg(rc == KERN_SUCCESS, ("%rc\n", rc));
    123     }
    124 
    125     return VINF_SUCCESS; /* ignore any errors for now */
    126 }
    127 
    128 
    129 /**
    130  * Native kernel thread wrapper function.
    131  *
    132  * This will forward to rtThreadMain and do termination upon return.
    133  *
    134  * @param pvArg         Pointer to the argument package.
    135  * @param Ignored       Wait result, which we ignore.
    136  */
    137 static void rtThreadNativeMain(void *pvArg, wait_result_t Ignored)
    138 {
    139     const thread_t Self = current_thread();
    140 
    141     rtThreadMain((PRTR0THREADARGS)pvArg, (RTNATIVETHREAD)Self);
    142 
    143     kern_return_t rc = thread_terminate(Self);
    144     AssertFatalMsgFailed(("rc=%d\n", rc));
    145 }
    146 
    147 
    148 int rtThreadNativeCreate(PRTR0THREADARGS pArgs, PRTNATIVETHREAD pNativeThread)
    149 {
    150     thread_t NativeThread;
    151     kern_return_t rc = kernel_thread_start(rtThreadNativeMain, pArgs, &NativeThread);
    152     if (rc == KERN_SUCCESS)
    153     {
    154         *pNativeThread = (RTNATIVETHREAD)NativeThread;
    155         thread_deallocate(NativeThread);
    156         return VINF_SUCCESS;
    157     }
    158     return RTErrConvertFromMachKernReturn(rc);
    159 }
    160 
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette