Changeset 24180 in vbox for trunk/src/VBox
- Timestamp:
- Oct 30, 2009 10:51:49 AM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 54127
- Location:
- trunk/src/VBox/Runtime/r0drv
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/mpnotification-r0drv.c
r22052 r24180 81 81 * make use of this to avoid having restart at the list head after each callback. */ 82 82 static uint32_t volatile g_iRTMpGeneration; 83 /** The number of RTMpNotification users.84 * This is incremented on init and decremented on termination. */85 static uint32_t volatile g_cRTMpUsers = 0;86 83 87 84 … … 96 93 void rtMpNotificationDoCallbacks(RTMPEVENT enmEvent, RTCPUID idCpu) 97 94 { 98 PRTMPNOTIFYREG pCur;99 RTSPINLOCK TMP Tmp;100 RTSPINLOCK hSpinlock;95 PRTMPNOTIFYREG pCur; 96 RTSPINLOCK hSpinlock; 97 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER; 101 98 102 99 /* … … 166 163 RTDECL(int) RTMpNotificationRegister(PFNRTMPNOTIFICATION pfnCallback, void *pvUser) 167 164 { 168 PRTMPNOTIFYREG pCur;169 PRTMPNOTIFYREG pNew;170 RTSPINLOCKTMP Tmp;165 PRTMPNOTIFYREG pCur; 166 PRTMPNOTIFYREG pNew; 167 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER; 171 168 172 169 /* … … 234 231 RTDECL(int) RTMpNotificationDeregister(PFNRTMPNOTIFICATION pfnCallback, void *pvUser) 235 232 { 236 PRTMPNOTIFYREG pPrev;237 PRTMPNOTIFYREG pCur;238 RTSPINLOCKTMP Tmp;233 PRTMPNOTIFYREG pPrev; 234 PRTMPNOTIFYREG pCur; 235 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER; 239 236 240 237 /* … … 284 281 int rtR0MpNotificationInit(void) 285 282 { 286 int rc = VINF_SUCCESS; 287 288 if (ASMAtomicIncS32(&g_cRTMpUsers) == 1) 289 { 290 rc = RTSpinlockCreate((PRTSPINLOCK)&g_hRTMpNotifySpinLock); 283 int rc = RTSpinlockCreate((PRTSPINLOCK)&g_hRTMpNotifySpinLock); 284 if (RT_SUCCESS(rc)) 285 { 286 rc = rtR0MpNotificationNativeInit(); 291 287 if (RT_SUCCESS(rc)) 292 { 293 rc = rtR0MpNotificationNativeInit(); 294 if (RT_SUCCESS(rc)) 295 return rc; 296 297 RTSpinlockDestroy(g_hRTMpNotifySpinLock); 298 g_hRTMpNotifySpinLock = NIL_RTSPINLOCK; 299 } 300 ASMAtomicDecS32(&g_cRTMpUsers); 288 return rc; 289 290 RTSpinlockDestroy(g_hRTMpNotifySpinLock); 291 g_hRTMpNotifySpinLock = NIL_RTSPINLOCK; 301 292 } 302 293 return rc; … … 306 297 void rtR0MpNotificationTerm(void) 307 298 { 308 RTSPINLOCK hSpinlock = g_hRTMpNotifySpinLock; 309 if (hSpinlock != NIL_RTSPINLOCK) 310 { 311 AssertMsg(g_cRTMpUsers > 0, ("%d\n", g_cRTMpUsers)); 312 if (ASMAtomicDecS32(&g_cRTMpUsers) == 0) 313 { 314 315 PRTMPNOTIFYREG pHead; 316 RTSPINLOCKTMP Tmp; 317 318 rtR0MpNotificationNativeTerm(); 319 320 /* pick up the list and the spinlock. */ 321 RTSpinlockAcquire(hSpinlock, &Tmp); 322 ASMAtomicWriteSize(&g_hRTMpNotifySpinLock, NIL_RTSPINLOCK); 323 pHead = g_pRTMpCallbackHead; 324 g_pRTMpCallbackHead = NULL; 325 ASMAtomicIncU32(&g_iRTMpGeneration); 326 RTSpinlockRelease(hSpinlock, &Tmp); 327 328 /* free the list. */ 329 while (pHead) 330 { 331 PRTMPNOTIFYREG pFree = pHead; 332 pHead = pHead->pNext; 333 334 pFree->pNext = NULL; 335 pFree->pfnCallback = NULL; 336 RTMemFree(pFree); 337 } 338 339 RTSpinlockDestroy(hSpinlock); 340 } 341 } 342 } 343 299 PRTMPNOTIFYREG pHead; 300 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER; 301 RTSPINLOCK hSpinlock = g_hRTMpNotifySpinLock; 302 AssertReturnVoid(hSpinlock != NIL_RTSPINLOCK); 303 304 rtR0MpNotificationNativeTerm(); 305 306 /* pick up the list and the spinlock. */ 307 RTSpinlockAcquire(hSpinlock, &Tmp); 308 ASMAtomicWriteSize(&g_hRTMpNotifySpinLock, NIL_RTSPINLOCK); 309 pHead = g_pRTMpCallbackHead; 310 g_pRTMpCallbackHead = NULL; 311 ASMAtomicIncU32(&g_iRTMpGeneration); 312 RTSpinlockRelease(hSpinlock, &Tmp); 313 314 /* free the list. */ 315 while (pHead) 316 { 317 PRTMPNOTIFYREG pFree = pHead; 318 pHead = pHead->pNext; 319 320 pFree->pNext = NULL; 321 pFree->pfnCallback = NULL; 322 RTMemFree(pFree); 323 } 324 325 RTSpinlockDestroy(hSpinlock); 326 } 327 -
trunk/src/VBox/Runtime/r0drv/powernotification-r0drv.c
r22877 r24180 82 82 * make use of this to avoid having restart at the list head after each callback. */ 83 83 static uint32_t volatile g_iRTPowerGeneration; 84 /** The number of RTPowerNotification users.85 * This is incremented on init and decremented on termination. */86 static uint32_t volatile g_cRTPowerUsers = 0;87 84 88 85 … … 92 89 { 93 90 PRTPOWERNOTIFYREG pCur; 94 RTSPINLOCK TMP Tmp = RTSPINLOCKTMP_INITIALIZER;95 RTSPINLOCK hSpinlock;91 RTSPINLOCK hSpinlock; 92 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER; 96 93 97 94 /* … … 162 159 RTDECL(int) RTPowerNotificationRegister(PFNRTPOWERNOTIFICATION pfnCallback, void *pvUser) 163 160 { 164 PRTPOWERNOTIFYREG pCur;165 PRTPOWERNOTIFYREG pNew;166 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER;161 PRTPOWERNOTIFYREG pCur; 162 PRTPOWERNOTIFYREG pNew; 163 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER; 167 164 168 165 /* … … 230 227 RTDECL(int) RTPowerNotificationDeregister(PFNRTPOWERNOTIFICATION pfnCallback, void *pvUser) 231 228 { 232 PRTPOWERNOTIFYREG pPrev;233 PRTPOWERNOTIFYREG pCur;234 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER;229 PRTPOWERNOTIFYREG pPrev; 230 PRTPOWERNOTIFYREG pCur; 231 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER; 235 232 236 233 /* … … 280 277 int rtR0PowerNotificationInit(void) 281 278 { 282 int rc = VINF_SUCCESS; 283 284 if (ASMAtomicIncU32(&g_cRTPowerUsers) == 1) 285 { 286 rc = RTSpinlockCreate((PRTSPINLOCK)&g_hRTPowerNotifySpinLock); 287 if (RT_SUCCESS(rc)) 288 { 289 /** @todo OS specific init here */ 290 return rc; 279 int rc = RTSpinlockCreate((PRTSPINLOCK)&g_hRTPowerNotifySpinLock); 280 if (RT_SUCCESS(rc)) 281 { 282 /** @todo OS specific init here */ 283 return rc; 291 284 #if 0 292 293 285 RTSpinlockDestroy(g_hRTPowerNotifySpinLock); 286 g_hRTPowerNotifySpinLock = NIL_RTSPINLOCK; 294 287 #endif 295 }296 ASMAtomicDecU32(&g_cRTPowerUsers);297 288 } 298 289 return rc; … … 302 293 void rtR0PowerNotificationTerm(void) 303 294 { 304 RTSPINLOCK hSpinlock = g_hRTPowerNotifySpinLock; 305 if (hSpinlock != NIL_RTSPINLOCK) 306 { 307 AssertMsg(g_cRTPowerUsers > 0, ("%d\n", g_cRTPowerUsers)); 308 if (ASMAtomicDecU32(&g_cRTPowerUsers) == 0) 309 { 310 PRTPOWERNOTIFYREG pHead; 311 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER; 312 313 /** @todo OS specific term here */ 314 315 /* pick up the list and the spinlock. */ 316 RTSpinlockAcquire(hSpinlock, &Tmp); 317 ASMAtomicWriteSize(&g_hRTPowerNotifySpinLock, NIL_RTSPINLOCK); 318 pHead = g_pRTPowerCallbackHead; 319 g_pRTPowerCallbackHead = NULL; 320 ASMAtomicIncU32(&g_iRTPowerGeneration); 321 RTSpinlockRelease(hSpinlock, &Tmp); 322 323 /* free the list. */ 324 while (pHead) 325 { 326 PRTPOWERNOTIFYREG pFree = pHead; 327 pHead = pHead->pNext; 328 329 pFree->pNext = NULL; 330 pFree->pfnCallback = NULL; 331 RTMemFree(pFree); 332 } 333 334 RTSpinlockDestroy(hSpinlock); 335 } 336 } 337 } 338 295 PRTPOWERNOTIFYREG pHead; 296 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER; 297 RTSPINLOCK hSpinlock = g_hRTPowerNotifySpinLock; 298 AssertReturnVoid(hSpinlock != NIL_RTSPINLOCK); 299 300 /** @todo OS specific term here */ 301 302 /* pick up the list and the spinlock. */ 303 RTSpinlockAcquire(hSpinlock, &Tmp); 304 ASMAtomicWriteSize(&g_hRTPowerNotifySpinLock, NIL_RTSPINLOCK); 305 pHead = g_pRTPowerCallbackHead; 306 g_pRTPowerCallbackHead = NULL; 307 ASMAtomicIncU32(&g_iRTPowerGeneration); 308 RTSpinlockRelease(hSpinlock, &Tmp); 309 310 /* free the list. */ 311 while (pHead) 312 { 313 PRTPOWERNOTIFYREG pFree = pHead; 314 pHead = pHead->pNext; 315 316 pFree->pNext = NULL; 317 pFree->pfnCallback = NULL; 318 RTMemFree(pFree); 319 } 320 321 RTSpinlockDestroy(hSpinlock); 322 } 323
Note:
See TracChangeset
for help on using the changeset viewer.