Changeset 19991 in vbox
- Timestamp:
- May 25, 2009 10:41:07 AM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 47697
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/PDMCritSect.cpp
r19735 r19991 5 5 6 6 /* 7 * Copyright (C) 2006-200 7Sun Microsystems, Inc.7 * Copyright (C) 2006-2009 Sun Microsystems, Inc. 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 20 20 */ 21 21 22 //#define PDM_WITH_R3R0_CRIT_SECT 22 23 23 24 /******************************************************************************* … … 29 30 #include <VBox/mm.h> 30 31 #include <VBox/vm.h> 32 31 33 #include <VBox/err.h> 32 33 34 #include <VBox/log.h> 35 #ifdef PDM_WITH_R3R0_CRIT_SECT 36 # include <VBox/sup.h> 37 #endif 34 38 #include <iprt/asm.h> 35 39 #include <iprt/assert.h> 40 #include <iprt/string.h> 36 41 #include <iprt/thread.h> 37 #include <iprt/string.h>38 42 39 43 … … 112 116 { 113 117 VM_ASSERT_EMT(pVM); 118 119 #ifdef PDM_WITH_R3R0_CRIT_SECT 120 /* 121 * Allocate the semaphore. 122 */ 123 AssertCompile(sizeof(SUPSEMEVENT) == sizeof(pCritSect->Core.EventSem)); 124 int rc = SUPSemEventCreate(pVM->pSession, (PSUPSEMEVENT)&pCritSect->Core.EventSem); 125 #else 114 126 int rc = RTCritSectInit(&pCritSect->Core); 127 #endif 115 128 if (RT_SUCCESS(rc)) 116 129 { 117 pCritSect->pVMR3 = pVM; 118 pCritSect->pVMR0 = pVM->pVMR0; 119 pCritSect->pVMRC = pVM->pVMRC; 120 pCritSect->pvKey = pvKey; 121 pCritSect->EventToSignal = NIL_RTSEMEVENT; 122 pCritSect->pNext = pVM->pdm.s.pCritSects; 123 pCritSect->pszName = RTStrDup(pszName); 130 #ifdef PDM_WITH_R3R0_CRIT_SECT 131 /* 132 * Initialize the structure (first bit is c&p from RTCritSectInitEx). 133 */ 134 pCritSect->Core.u32Magic = RTCRITSECT_MAGIC; 135 pCritSect->Core.fFlags = 0; 136 pCritSect->Core.cNestings = 0; 137 pCritSect->Core.cLockers = -1; 138 pCritSect->Core.NativeThreadOwner = NIL_RTNATIVETHREAD; 139 pCritSect->Core.Strict.ThreadOwner = NIL_RTTHREAD; 140 pCritSect->Core.Strict.pszEnterFile = NULL; 141 pCritSect->Core.Strict.u32EnterLine = 0; 142 pCritSect->Core.Strict.uEnterId = 0; 143 #endif 144 pCritSect->pVMR3 = pVM; 145 pCritSect->pVMR0 = pVM->pVMR0; 146 pCritSect->pVMRC = pVM->pVMRC; 147 pCritSect->pvKey = pvKey; 148 pCritSect->EventToSignal = NIL_RTSEMEVENT; 149 pCritSect->pNext = pVM->pdm.s.pCritSects; 150 pCritSect->pszName = RTStrDup(pszName); 124 151 pVM->pdm.s.pCritSects = pCritSect; 125 152 STAMR3RegisterF(pVM, &pCritSect->StatContentionRZLock, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PDM/CritSects/%s/ContentionRZLock", pszName); … … 185 212 static int pdmR3CritSectDeleteOne(PVM pVM, PPDMCRITSECTINT pCritSect, PPDMCRITSECTINT pPrev, bool fFinal) 186 213 { 187 /* ulink */ 214 #ifdef PDM_WITH_R3R0_CRIT_SECT 215 /* 216 * Assert free waiters and so on (c&p from RTCritSectDelete). 217 */ 218 Assert(pCritSect->Core.u32Magic == RTCRITSECT_MAGIC); 219 Assert(pCritSect->Core.cNestings == 0); 220 Assert(pCritSect->Core.cLockers == -1); 221 Assert(pCritSect->Core.NativeThreadOwner == NIL_RTNATIVETHREAD); 222 #endif 223 224 /* 225 * Unlink it. 226 */ 188 227 if (pPrev) 189 228 pPrev->pNext = pCritSect->pNext; … … 191 230 pVM->pdm.s.pCritSects = pCritSect->pNext; 192 231 193 /* delete */ 232 /* 233 * Delete it (parts taken from RTCritSectDelete). 234 * In case someone is waiting we'll signal the semaphore cLockers + 1 times. 235 */ 236 #ifdef PDM_WITH_R3R0_CRIT_SECT 237 ASMAtomicWriteU32(&pCritSect->Core.u32Magic, 0); 238 SUPSEMEVENT hEvent = (SUPSEMEVENT)pCritSect->Core.EventSem; 239 pCritSect->Core.EventSem = NIL_RTSEMEVENT; 240 while (pCritSect->Core.cLockers-- >= 0) 241 SUPSemEventSignal(pVM->pSession, hEvent); 242 ASMAtomicWriteS32(&pCritSect->Core.cLockers, -1); 243 int rc = SUPSemEventClose(pVM->pSession, hEvent); 244 AssertRC(rc); 245 #endif 194 246 pCritSect->pNext = NULL; 195 247 pCritSect->pvKey = NULL; … … 208 260 #endif 209 261 } 210 return RTCritSectDelete(&pCritSect->Core); 262 #ifndef PDM_WITH_R3R0_CRIT_SECT 263 int rc = RTCritSectDelete(&pCritSect->Core); 264 #endif 265 return rc; 211 266 } 212 267 … … 306 361 { 307 362 PPDMCRITSECT pCritSect = pVCpu->pdm.s.apQueuedCritSectsLeaves[i]; 363 #ifdef PDM_WITH_R3R0_CRIT_SECT 364 int rc = pdmCritSectLeave(pCritSect); 365 #else 308 366 int rc = RTCritSectLeave(&pCritSect->s.Core); 367 #endif 309 368 LogFlow(("PDMR3CritSectFF: %p - %Rrc\n", pCritSect, rc)); 310 369 AssertRC(rc);
Note:
See TracChangeset
for help on using the changeset viewer.