Changeset 22650 in vbox
- Timestamp:
- Sep 1, 2009 11:54:15 AM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/spinlock.h
r22127 r22650 66 66 # define RTSPINLOCKTMP_INITIALIZER { 0 } 67 67 68 # elif defined(RT_OS_DARWIN) || defined(RT_OS_ SOLARIS)68 # elif defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_SOLARIS) 69 69 /** The saved [R|E]FLAGS. */ 70 70 RTCCUINTREG uFlags; 71 71 # define RTSPINLOCKTMP_INITIALIZER { 0 } 72 72 73 # elif defined(RT_OS_OS2) || defined(RT_OS_FREEBSD) /** @todo r=bird: FreeBSD is probably doing the wrong thing here. */73 # elif defined(RT_OS_OS2) 74 74 /** The saved [R|E]FLAGS. (dummy) */ 75 75 RTCCUINTREG uFlags; -
trunk/src/VBox/Runtime/r0drv/freebsd/spinlock-r0drv-freebsd.c
r22580 r22650 77 77 RT_ASSERT_PREEMPTIBLE(); 78 78 AssertCompile(sizeof(RTSPINLOCKINTERNAL) > sizeof(void *)); 79 PRTSPINLOCKINTERNAL p SpinlockInt = (PRTSPINLOCKINTERNAL)RTMemAllocZ(sizeof(*pSpinlockInt));80 if (!p SpinlockInt)79 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)RTMemAllocZ(sizeof(*pThis)); 80 if (!pThis) 81 81 return VERR_NO_MEMORY; 82 82 … … 84 84 * Initialize & return. 85 85 */ 86 p SpinlockInt->u32Magic = RTSPINLOCK_MAGIC;87 p SpinlockInt->fLocked = 0;88 *pSpinlock = p SpinlockInt;86 pThis->u32Magic = RTSPINLOCK_MAGIC; 87 pThis->fLocked = 0; 88 *pSpinlock = pThis; 89 89 return VINF_SUCCESS; 90 90 } … … 97 97 */ 98 98 RT_ASSERT_INTS_ON(); 99 PRTSPINLOCKINTERNAL p SpinlockInt= (PRTSPINLOCKINTERNAL)Spinlock;100 if (!p SpinlockInt)99 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock; 100 if (!pThis) 101 101 return VERR_INVALID_PARAMETER; 102 AssertMsgReturn(p SpinlockInt->u32Magic == RTSPINLOCK_MAGIC,103 ("Invalid spinlock %p magic=%#x\n", p SpinlockInt, pSpinlockInt->u32Magic),102 AssertMsgReturn(pThis->u32Magic == RTSPINLOCK_MAGIC, 103 ("Invalid spinlock %p magic=%#x\n", pThis, pThis->u32Magic), 104 104 VERR_INVALID_PARAMETER); 105 105 … … 107 107 * Make the lock invalid and release the memory. 108 108 */ 109 ASMAtomicIncU32(&p SpinlockInt->u32Magic);110 RTMemFree(p SpinlockInt);109 ASMAtomicIncU32(&pThis->u32Magic); 110 RTMemFree(pThis); 111 111 return VINF_SUCCESS; 112 112 } … … 115 115 RTDECL(void) RTSpinlockAcquireNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp) 116 116 { 117 PRTSPINLOCKINTERNAL p SpinlockInt= (PRTSPINLOCKINTERNAL)Spinlock;118 AssertPtr(p SpinlockInt);119 Assert(p SpinlockInt->u32Magic == RTSPINLOCK_MAGIC);117 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock; 118 AssertPtr(pThis); 119 Assert(pThis->u32Magic == RTSPINLOCK_MAGIC); 120 120 RT_ASSERT_PREEMPT_CPUID_VAR(); 121 Assert(pTmp->uFlags == 0); 121 122 122 123 for (;;) 123 124 { 124 pTmp->uFlags = ASMGetFlags(); 125 ASMIntDisable(); 125 pTmp->uFlags = ASMIntDisableFlags(); 126 126 critical_enter(); 127 127 128 for (int c = 50; c > 0; c--) 129 if (ASMAtomicCmpXchgU32(&pSpinlockInt->fLocked, 1, 0)) 128 int c = 50; 129 for (;;) 130 { 131 if (ASMAtomicCmpXchgU32(&pThis->fLocked, 1, 0)) 130 132 { 131 RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED(p SpinlockInt);133 RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED(pThis); 132 134 return; 133 135 } 134 else 135 cpu_spinwait(); 136 if (--c <= 0) 137 break; 138 cpu_spinwait(); 139 } 136 140 137 141 /* Enable interrupts while we sleep. */ … … 145 149 RTDECL(void) RTSpinlockReleaseNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp) 146 150 { 147 PRTSPINLOCKINTERNAL p SpinlockInt= (PRTSPINLOCKINTERNAL)Spinlock;151 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock; 148 152 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS(); 149 153 150 AssertPtr(p SpinlockInt);151 Assert(p SpinlockInt->u32Magic == RTSPINLOCK_MAGIC);152 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE(p SpinlockInt);153 NOREF(pTmp); 154 155 if (!ASMAtomicCmpXchgU32(&pSpinlockInt->fLocked, 0, 1))156 AssertMsgFailed(("Spinlock %p was not locked!\n", pSpinlockInt)); 154 AssertPtr(pThis); 155 Assert(pThis->u32Magic == RTSPINLOCK_MAGIC); 156 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE(pThis); 157 158 if (!ASMAtomicCmpXchgU32(&pThis->fLocked, 0, 1)) 159 AssertMsgFailed(("Spinlock %p was not locked!\n", pThis)); 160 157 161 ASMSetFlags(pTmp->uFlags); 158 159 162 critical_exit(); 163 pTmp->uFlags = 0; 160 164 } 161 165 … … 163 167 RTDECL(void) RTSpinlockAcquire(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp) 164 168 { 165 PRTSPINLOCKINTERNAL p SpinlockInt= (PRTSPINLOCKINTERNAL)Spinlock;169 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock; 166 170 RT_ASSERT_PREEMPT_CPUID_VAR(); 167 AssertPtr(pSpinlockInt); 168 Assert(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC); 171 AssertPtr(pThis); 172 Assert(pThis->u32Magic == RTSPINLOCK_MAGIC); 173 #ifdef RT_STRICT 174 Assert(pTmp->uFlags == 0); 175 pTmp->uFlags = 0; 176 #endif 169 177 170 178 NOREF(pTmp); … … 173 181 { 174 182 critical_enter(); 175 for (int c = 50; c > 0; c--) 176 if (ASMAtomicCmpXchgU32(&pSpinlockInt->fLocked, 1, 0)) 183 184 int c = 50; 185 for (;;) 186 { 187 if (ASMAtomicCmpXchgU32(&pThis->fLocked, 1, 0)) 177 188 { 178 RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED(p SpinlockInt);189 RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED(pThis); 179 190 return; 180 191 } 181 else 182 cpu_spinwait(); 192 if (--c <= 0) 193 break; 194 cpu_spinwait(); 195 } 183 196 184 197 critical_exit(); … … 190 203 RTDECL(void) RTSpinlockRelease(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp) 191 204 { 192 PRTSPINLOCKINTERNAL p SpinlockInt= (PRTSPINLOCKINTERNAL)Spinlock;205 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock; 193 206 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS(); 194 207 195 AssertPtr(pSpinlockInt); 196 Assert(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC); 197 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE(pSpinlockInt); 198 208 AssertPtr(pThis); 209 Assert(pThis->u32Magic == RTSPINLOCK_MAGIC); 210 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE(pThis); 211 #ifdef RT_STRICT 212 Assert(pTmp->uFlags == 42); 213 pTmp->uFlags = 0; 214 #endif 199 215 NOREF(pTmp); 200 216 201 if (!ASMAtomicCmpXchgU32(&p SpinlockInt->fLocked, 0, 1))202 AssertMsgFailed(("Spinlock %p was not locked!\n", p SpinlockInt));217 if (!ASMAtomicCmpXchgU32(&pThis->fLocked, 0, 1)) 218 AssertMsgFailed(("Spinlock %p was not locked!\n", pThis)); 203 219 204 220 critical_exit();
Note:
See TracChangeset
for help on using the changeset viewer.