VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/freebsd/thread-r0drv-freebsd.c@ 20916

Last change on this file since 20916 was 20554, checked in by vboxsync, 16 years ago

thread-r0drv-freebsd.c: changed (C) to Sun.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1/* $Id: thread-r0drv-freebsd.c 20554 2009-06-14 17:22:59Z vboxsync $ */
2/** @file
3 * IPRT - Threads (Part 1), Ring-0 Driver, FreeBSD.
4 */
5
6/*
7 * Copyright (C) 2007-2009 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31/*******************************************************************************
32* Header Files *
33*******************************************************************************/
34#include "the-freebsd-kernel.h"
35
36#include <iprt/thread.h>
37#include <iprt/err.h>
38#include <iprt/assert.h>
39
40#include "internal/thread.h"
41
42
43RTDECL(RTNATIVETHREAD) RTThreadNativeSelf(void)
44{
45 return (RTNATIVETHREAD)curthread;
46}
47
48
49RTDECL(int) RTThreadSleep(unsigned cMillies)
50{
51 int rc;
52 int cTicks;
53
54 /*
55 * 0 ms sleep -> yield.
56 */
57 if (!cMillies)
58 {
59 RTThreadYield();
60 return VINF_SUCCESS;
61 }
62
63 /*
64 * Translate milliseconds into ticks and go to sleep.
65 */
66 if (cMillies != RT_INDEFINITE_WAIT)
67 {
68 if (hz == 1000)
69 cTicks = cMillies;
70 else if (hz == 100)
71 cTicks = cMillies / 10;
72 else
73 {
74 int64_t cTicks64 = ((uint64_t)cMillies * hz) / 1000;
75 cTicks = (int)cTicks64;
76 if (cTicks != cTicks64)
77 cTicks = INT_MAX;
78 }
79 }
80 else
81 cTicks = 0; /* requires giant lock! */
82
83 rc = tsleep((void *)RTThreadSleep,
84 PZERO | PCATCH,
85 "iprtsl", /* max 6 chars */
86 cTicks);
87 switch (rc)
88 {
89 case 0:
90 return VINF_SUCCESS;
91 case EWOULDBLOCK:
92 return VERR_TIMEOUT;
93 case EINTR:
94 case ERESTART:
95 return VERR_INTERRUPTED;
96 default:
97 AssertMsgFailed(("%d\n", rc));
98 return VERR_NO_TRANSLATION;
99 }
100}
101
102
103RTDECL(bool) RTThreadYield(void)
104{
105 uio_yield();
106 return false; /** @todo figure this one ... */
107}
108
109
110RTDECL(bool) RTThreadPreemptIsEnabled(RTTHREAD hThread)
111{
112 Assert(hThread == NIL_RTTHREAD);
113
114 return curthread->td_critnest == 0;
115}
116
117
118RTDECL(bool) RTThreadPreemptIsPending(RTTHREAD hThread)
119{
120 Assert(hThread == NIL_RTTHREAD);
121
122 return curthread->td_owepreempt == 1;
123}
124
125
126RTDECL(bool) RTThreadPreemptIsPendingTrusty(void)
127{
128 /* yes, RTThreadPreemptIsPending is reliable. */
129 return true;
130}
131
132
133RTDECL(void) RTThreadPreemptDisable(PRTTHREADPREEMPTSTATE pState)
134{
135 AssertPtr(pState);
136 Assert(pState->uchDummy != 42);
137 pState->uchDummy = 42;
138
139 critical_enter();
140}
141
142
143RTDECL(void) RTThreadPreemptRestore(PRTTHREADPREEMPTSTATE pState)
144{
145 AssertPtr(pState);
146 Assert(pState->uchDummy == 42);
147 pState->uchDummy = 0;
148
149 critical_exit();
150}
151
Note: See TracBrowser for help on using the repository browser.

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