VirtualBox

Ignore:
Timestamp:
Aug 11, 2016 6:25:33 PM (8 years ago)
Author:
vboxsync
Message:

r0drv/netbsd: re-import r0drv support for NetBSD on top of svn copy of
FreeBSD sources for cases where the differences are obvious and
minimal.

From Haomai Wang GSoC project with additional changes by Arto Huusko.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r0drv/netbsd/thread-r0drv-netbsd.c

    r63342 r63345  
    11/* $Id$ */
    22/** @file
    3  * IPRT - Threads (Part 1), Ring-0 Driver, FreeBSD.
     3 * IPRT - Threads (Part 1), Ring-0 Driver, NetBSD.
    44 */
    55
    66/*
    7  * Copyright (C) 2007-2016 Oracle Corporation
     7 * Copyright (C) 2007-2011 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2525 */
    2626
    27 
    2827/*********************************************************************************************************************************
    2928*   Header Files                                                                                                                 *
    3029*********************************************************************************************************************************/
    31 #include "the-freebsd-kernel.h"
     30#include "the-netbsd-kernel.h"
    3231#include "internal/iprt.h"
    3332#include <iprt/thread.h>
     
    4342RTDECL(RTNATIVETHREAD) RTThreadNativeSelf(void)
    4443{
    45     return (RTNATIVETHREAD)curthread;
     44    return (RTNATIVETHREAD)curlwp;
    4645}
    4746
    4847
    49 static int rtR0ThreadFbsdSleepCommon(RTMSINTERVAL cMillies)
     48static int rtR0ThreadNbsdSleepCommon(RTMSINTERVAL cMillies)
    5049{
    5150    int rc;
     
    103102RTDECL(int) RTThreadSleep(RTMSINTERVAL cMillies)
    104103{
    105     return rtR0ThreadFbsdSleepCommon(cMillies);
     104    return rtR0ThreadNbsdSleepCommon(cMillies);
    106105}
    107106
     
    109108RTDECL(int) RTThreadSleepNoLog(RTMSINTERVAL cMillies)
    110109{
    111     return rtR0ThreadFbsdSleepCommon(cMillies);
     110    return rtR0ThreadNbsdSleepCommon(cMillies);
    112111}
    113112
     
    115114RTDECL(bool) RTThreadYield(void)
    116115{
    117 #if __FreeBSD_version >= 900032
    118     kern_yield(curthread->td_user_pri);
    119 #else
    120     uio_yield();
    121 #endif
    122     return false; /** @todo figure this one ... */
     116    yield();
     117    return true;
    123118}
    124119
     
    128123    Assert(hThread == NIL_RTTHREAD);
    129124
    130     return curthread->td_critnest == 0
    131         && ASMIntAreEnabled(); /** @todo is there a native freebsd function/macro for this? */
     125    return curlwp->l_dopreempt == 0
     126        && ASMIntAreEnabled(); /** @todo is there a native netbsd function/macro for this? */
    132127}
    133128
     
    137132    Assert(hThread == NIL_RTTHREAD);
    138133
    139     return curthread->td_owepreempt == 1;
     134    return curlwp->l_dopreempt;
    140135}
    141136
     
    154149}
    155150
    156 
    157151RTDECL(void) RTThreadPreemptDisable(PRTTHREADPREEMPTSTATE pState)
    158152{
    159153    AssertPtr(pState);
    160     Assert(pState->u32Reserved == 0);
    161     pState->u32Reserved = 42;
    162154
    163     critical_enter();
    164     RT_ASSERT_PREEMPT_CPUID_DISABLE(pState);
     155    curlwp->l_nopreempt++;
     156    __insn_barrier();
    165157}
    166158
     
    168160RTDECL(void) RTThreadPreemptRestore(PRTTHREADPREEMPTSTATE pState)
    169161{
     162
    170163    AssertPtr(pState);
    171     Assert(pState->u32Reserved == 42);
    172     pState->u32Reserved = 0;
    173 
    174     RT_ASSERT_PREEMPT_CPUID_RESTORE(pState);
    175     critical_exit();
     164    __insn_barrier();
     165    if (--curlwp->l_nopreempt != 0)
     166        return;
     167    __insn_barrier();
     168    if (__predict_false(curlwp->l_dopreempt))
     169        kpreempt(0);
     170    __insn_barrier();
    176171}
    177 
    178172
    179173RTDECL(bool) RTThreadIsInInterrupt(RTTHREAD hThread)
    180174{
    181175    Assert(hThread == NIL_RTTHREAD); NOREF(hThread);
    182     /** @todo FreeBSD: Implement RTThreadIsInInterrupt. Required for guest
     176    /** @todo NetBSD: Implement RTThreadIsInInterrupt. Required for guest
    183177     *        additions! */
    184178    return !ASMIntAreEnabled();
    185179}
    186 
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