Changeset 22131 in vbox for trunk/src/VBox/Runtime/r0drv
- Timestamp:
- Aug 10, 2009 1:07:43 PM (15 years ago)
- Location:
- trunk/src/VBox/Runtime/r0drv
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/linux/spinlock-r0drv-linux.c
r22130 r22131 58 58 /** The linux spinlock structure. */ 59 59 spinlock_t Spinlock; 60 #if !defined(CONFIG_SMP) || defined(RT_ARCH_AMD64) 60 #ifdef RT_MORE_STRICT 61 /** The idAssertCpu variable before acquring the lock for asserting after 62 * releasing the spinlock. */ 63 RTCPUID volatile idAssertCpu; 64 /** The CPU that owns the lock. */ 65 RTCPUID volatile idCpuOwner; 66 #elif !defined(CONFIG_SMP) || defined(RT_ARCH_AMD64) 61 67 /** A placeholder on Uni systems so we won't piss off RTMemAlloc(). */ 62 68 void *pvUniDummy; … … 71 77 * Allocate. 72 78 */ 73 PRTSPINLOCKINTERNAL p SpinlockInt;79 PRTSPINLOCKINTERNAL pThis; 74 80 Assert(sizeof(RTSPINLOCKINTERNAL) > sizeof(void *)); 75 p SpinlockInt = (PRTSPINLOCKINTERNAL)RTMemAlloc(sizeof(*pSpinlockInt));76 if (!p SpinlockInt)81 pThis = (PRTSPINLOCKINTERNAL)RTMemAlloc(sizeof(*pThis)); 82 if (!pThis) 77 83 return VERR_NO_MEMORY; 78 84 /* 79 85 * Initialize and return. 80 86 */ 81 pSpinlockInt->u32Magic = RTSPINLOCK_MAGIC; 82 spin_lock_init(&pSpinlockInt->Spinlock); 87 pThis->u32Magic = RTSPINLOCK_MAGIC; 88 #ifdef RT_MORE_STRICT 89 pThis->idCpuOwner = NIL_RTCPUID; 90 pThis->idAssertCpu = NIL_RTCPUID; 91 #endif 92 spin_lock_init(&pThis->Spinlock); 83 93 84 *pSpinlock = p SpinlockInt;94 *pSpinlock = pThis; 85 95 return VINF_SUCCESS; 86 96 } … … 93 103 * Validate input. 94 104 */ 95 PRTSPINLOCKINTERNAL p SpinlockInt= (PRTSPINLOCKINTERNAL)Spinlock;96 if (!p SpinlockInt)105 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock; 106 if (!pThis) 97 107 return VERR_INVALID_PARAMETER; 98 if (p SpinlockInt->u32Magic != RTSPINLOCK_MAGIC)108 if (pThis->u32Magic != RTSPINLOCK_MAGIC) 99 109 { 100 AssertMsgFailed(("Invalid spinlock %p magic=%#x\n", p SpinlockInt, pSpinlockInt->u32Magic));110 AssertMsgFailed(("Invalid spinlock %p magic=%#x\n", pThis, pThis->u32Magic)); 101 111 return VERR_INVALID_PARAMETER; 102 112 } 103 113 104 ASMAtomicIncU32(&p SpinlockInt->u32Magic);105 RTMemFree(p SpinlockInt);114 ASMAtomicIncU32(&pThis->u32Magic); 115 RTMemFree(pThis); 106 116 return VINF_SUCCESS; 107 117 } … … 111 121 RTDECL(void) RTSpinlockAcquireNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp) 112 122 { 113 PRTSPINLOCKINTERNAL p SpinlockInt= (PRTSPINLOCKINTERNAL)Spinlock;114 AssertMsg(pSpinlockInt && pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC,115 ("pSpinlockInt=%p u32Magic=%08x\n", pSpinlockInt, pSpinlockInt ? (int)pSpinlockInt->u32Magic : 0));116 NOREF(pSpinlockInt);123 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock; 124 RT_ASSERT_PREEMPT_CPUID_VAR(); 125 AssertMsg(pThis && pThis->u32Magic == RTSPINLOCK_MAGIC, 126 ("pThis=%p u32Magic=%08x\n", pThis, pThis ? (int)pThis->u32Magic : 0)); 117 127 118 spin_lock_irqsave(&pSpinlockInt->Spinlock, pTmp->flFlags); 128 spin_lock_irqsave(&pThis->Spinlock, pTmp->flFlags); 129 130 RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED(pThis); 119 131 } 120 132 RT_EXPORT_SYMBOL(RTSpinlockAcquireNoInts); … … 123 135 RTDECL(void) RTSpinlockReleaseNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp) 124 136 { 125 PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock; 126 AssertMsg(pSpinlockInt && pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC, 127 ("pSpinlockInt=%p u32Magic=%08x\n", pSpinlockInt, pSpinlockInt ? (int)pSpinlockInt->u32Magic : 0)); 128 NOREF(pSpinlockInt); 137 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock; 138 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS(); 129 139 130 spin_unlock_irqrestore(&pSpinlockInt->Spinlock, pTmp->flFlags); 140 AssertMsg(pThis && pThis->u32Magic == RTSPINLOCK_MAGIC, 141 ("pThis=%p u32Magic=%08x\n", pThis, pThis ? (int)pThis->u32Magic : 0)); 142 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE(pThis); 143 NOREF(pTmp); 144 145 spin_unlock_irqrestore(&pThis->Spinlock, pTmp->flFlags); 146 147 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASED(); 131 148 } 132 149 RT_EXPORT_SYMBOL(RTSpinlockReleaseNoInts); … … 135 152 RTDECL(void) RTSpinlockAcquire(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp) 136 153 { 137 PRTSPINLOCKINTERNAL p SpinlockInt= (PRTSPINLOCKINTERNAL)Spinlock;154 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock; 138 155 RT_ASSERT_PREEMPT_CPUID_VAR(); 139 AssertMsg(p SpinlockInt && pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC,140 ("p SpinlockInt=%p u32Magic=%08x\n", pSpinlockInt, pSpinlockInt ? (int)pSpinlockInt->u32Magic : 0));141 NOREF(p SpinlockInt); NOREF(pTmp);156 AssertMsg(pThis && pThis->u32Magic == RTSPINLOCK_MAGIC, 157 ("pThis=%p u32Magic=%08x\n", pThis, pThis ? (int)pThis->u32Magic : 0)); 158 NOREF(pTmp); 142 159 143 spin_lock(&p SpinlockInt->Spinlock);160 spin_lock(&pThis->Spinlock); 144 161 145 #ifdef RT_MORE_STRICT 146 { 147 RTCPUID const idAssertCpuNow = RTMpCpuId(); /* Spinlocks are not preemptible, so we cannot be rescheduled. */ 148 AssertMsg(idAssertCpu == idAssertCpuNow || idAssertCpu == NIL_RTCPUID, ("%#x, %#x\n", idAssertCpu, idAssertCpuNow)); 149 pTmp->flFlags = idAssertCpuNow; 150 } 151 #endif 162 RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED(pThis); 152 163 } 153 164 RT_EXPORT_SYMBOL(RTSpinlockAcquire); … … 156 167 RTDECL(void) RTSpinlockRelease(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp) 157 168 { 158 PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock; 159 #ifdef RT_MORE_STRICT 160 RTCPUID const idAssertCpu = pTmp->flFlags; 161 pTmp->flFlags = 0; 162 RT_ASSERT_PREEMPT_CPUID(); 163 #endif 164 AssertMsg(pSpinlockInt && pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC, 165 ("pSpinlockInt=%p u32Magic=%08x\n", pSpinlockInt, pSpinlockInt ? (int)pSpinlockInt->u32Magic : 0)); 166 NOREF(pSpinlockInt); NOREF(pTmp); 169 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock; 170 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS(); 171 AssertMsg(pThis && pThis->u32Magic == RTSPINLOCK_MAGIC, 172 ("pThis=%p u32Magic=%08x\n", pThis, pThis ? (int)pThis->u32Magic : 0)); 173 NOREF(pTmp); 174 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE(pThis); 167 175 168 spin_unlock(&p SpinlockInt->Spinlock);176 spin_unlock(&pThis->Spinlock); 169 177 170 #ifdef RT_MORE_STRICT 171 if (!RTThreadPreemptIsEnabled(NIL_RTTHREAD)) 172 RT_ASSERT_PREEMPT_CPUID(); 173 #endif 178 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASED(); 174 179 } 175 180 RT_EXPORT_SYMBOL(RTSpinlockRelease); -
trunk/src/VBox/Runtime/r0drv/solaris/spinlock-r0drv-solaris.c
r22130 r22131 58 58 /** A Solaris spinlock. */ 59 59 kmutex_t Mtx; 60 #ifdef RT_MORE_STRICT 61 /** The idAssertCpu variable before acquring the lock for asserting after 62 * releasing the spinlock. */ 63 RTCPUID volatile idAssertCpu; 64 /** The CPU that owns the lock. */ 65 RTCPUID volatile idCpuOwner; 66 #endif 60 67 } RTSPINLOCKINTERNAL, *PRTSPINLOCKINTERNAL; 61 68 … … 69 76 RT_ASSERT_PREEMPTIBLE(); 70 77 AssertCompile(sizeof(RTSPINLOCKINTERNAL) > sizeof(void *)); 71 PRTSPINLOCKINTERNAL p SpinlockInt = (PRTSPINLOCKINTERNAL)RTMemAlloc(sizeof(*pSpinlockInt));72 if (!p SpinlockInt)78 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)RTMemAlloc(sizeof(*pThis)); 79 if (!pThis) 73 80 return VERR_NO_MEMORY; 74 81 … … 76 83 * Initialize & return. 77 84 */ 78 p SpinlockInt->u32Magic = RTSPINLOCK_MAGIC;79 mutex_init(&p SpinlockInt->Mtx, "IPRT Spinlock", MUTEX_SPIN, (void *)ipltospl(DISP_LEVEL));80 *pSpinlock = p SpinlockInt;85 pThis->u32Magic = RTSPINLOCK_MAGIC; 86 mutex_init(&pThis->Mtx, "IPRT Spinlock", MUTEX_SPIN, (void *)ipltospl(DISP_LEVEL)); 87 *pSpinlock = pThis; 81 88 return VINF_SUCCESS; 82 89 } … … 89 96 */ 90 97 RT_ASSERT_INTS_ON(); 91 PRTSPINLOCKINTERNAL p SpinlockInt= (PRTSPINLOCKINTERNAL)Spinlock;92 if (!p SpinlockInt)98 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock; 99 if (!pThis) 93 100 return VERR_INVALID_PARAMETER; 94 AssertMsgReturn(p SpinlockInt->u32Magic == RTSPINLOCK_MAGIC,95 ("Invalid spinlock %p magic=%#x\n", p SpinlockInt, pSpinlockInt->u32Magic),101 AssertMsgReturn(pThis->u32Magic == RTSPINLOCK_MAGIC, 102 ("Invalid spinlock %p magic=%#x\n", pThis, pThis->u32Magic), 96 103 VERR_INVALID_PARAMETER); 97 104 … … 99 106 * Make the lock invalid and release the memory. 100 107 */ 101 ASMAtomicIncU32(&p SpinlockInt->u32Magic);102 mutex_destroy(&p SpinlockInt->Mtx);103 RTMemFree(p SpinlockInt);108 ASMAtomicIncU32(&pThis->u32Magic); 109 mutex_destroy(&pThis->Mtx); 110 RTMemFree(pThis); 104 111 return VINF_SUCCESS; 105 112 } … … 108 115 RTDECL(void) RTSpinlockAcquireNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp) 109 116 { 110 PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock; 111 AssertPtr(pSpinlockInt); 112 Assert(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC); 117 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock; 118 RT_ASSERT_PREEMPT_CPUID_VAR(); 119 120 AssertPtr(pThis); 121 Assert(pThis->u32Magic == RTSPINLOCK_MAGIC); 113 122 114 123 pTmp->uFlags = ASMIntDisableFlags(); 115 { 116 RT_ASSERT_PREEMPT_CPUID_VAR(); 117 mutex_enter(&pSpinlockInt->Mtx); 118 RT_ASSERT_PREEMPT_CPUID(); 119 } 124 mutex_enter(&pThis->Mtx); 125 126 RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED() 120 127 } 121 128 … … 123 130 RTDECL(void) RTSpinlockReleaseNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp) 124 131 { 125 PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock; 126 AssertPtr(pSpinlockInt); 127 Assert(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC); 132 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock; 133 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS(); 128 134 129 mutex_exit(&pSpinlockInt->Mtx); 135 AssertPtr(pThis); 136 Assert(pThis->u32Magic == RTSPINLOCK_MAGIC); 137 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE(pThis); 138 NOREF(pTmp); 139 140 mutex_exit(&pThis->Mtx); 130 141 ASMSetFlags(pTmp->uFlags); 142 143 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASED(); 131 144 } 132 145 … … 134 147 RTDECL(void) RTSpinlockAcquire(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp) 135 148 { 136 PRTSPINLOCKINTERNAL p SpinlockInt= (PRTSPINLOCKINTERNAL)Spinlock;149 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock; 137 150 RT_ASSERT_PREEMPT_CPUID_VAR(); 138 AssertPtr(p SpinlockInt);139 Assert(p SpinlockInt->u32Magic == RTSPINLOCK_MAGIC);151 AssertPtr(pThis); 152 Assert(pThis->u32Magic == RTSPINLOCK_MAGIC); 140 153 NOREF(pTmp); 141 154 142 mutex_enter(&p SpinlockInt->Mtx);155 mutex_enter(&pThis->Mtx); 143 156 144 #ifdef RT_MORE_STRICT 145 { 146 RTCPUID const idAssertCpuNow = RTMpCpuId(); /* Spinlocks are not preemptible, so we cannot be rescheduled. */ 147 AssertMsg(idAssertCpu == idAssertCpuNow || idAssertCpu == NIL_RTCPUID, ("%#x, %#x\n", idAssertCpu, idAssertCpuNow)); 148 pTmp->uFlags = idAssertCpuNow; 149 } 150 #endif 157 RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED() 151 158 } 152 159 … … 154 161 RTDECL(void) RTSpinlockRelease(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp) 155 162 { 156 PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock; 157 #ifdef RT_MORE_STRICT 158 RTCPUID const idAssertCpu = pTmp->uFlags; 159 pTmp->uFlags = 0; 160 RT_ASSERT_PREEMPT_CPUID(); 161 #endif 162 AssertPtr(pSpinlockInt); 163 Assert(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC); 163 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock; 164 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS(); 165 166 AssertPtr(pThis); 167 Assert(pThis->u32Magic == RTSPINLOCK_MAGIC); 168 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE(pThis); 164 169 NOREF(pTmp); 165 170 166 mutex_exit(&p SpinlockInt->Mtx);171 mutex_exit(&pThis->Mtx); 167 172 168 #ifdef RT_MORE_STRICT 169 if (!RTThreadPreemptIsEnabled(NIL_RTTHREAD)) 170 RT_ASSERT_PREEMPT_CPUID(); 171 #endif 173 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASED(); 172 174 } 173 175
Note:
See TracChangeset
for help on using the changeset viewer.