VirtualBox

Changeset 24180 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Oct 30, 2009 10:51:49 AM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
54127
Message:

IPRT: Drop the extra usage counting in powernotification-r0drv.c and mpnotification-r0drv.c. Initialize RTSPINLOCKTMP variables.

Location:
trunk/src/VBox/Runtime/r0drv
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r0drv/mpnotification-r0drv.c

    r22052 r24180  
    8181 * make use of this to avoid having restart at the list head after each callback. */
    8282static 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;
    8683
    8784
     
    9693void rtMpNotificationDoCallbacks(RTMPEVENT enmEvent, RTCPUID idCpu)
    9794{
    98     PRTMPNOTIFYREG pCur;
    99     RTSPINLOCKTMP Tmp;
    100     RTSPINLOCK hSpinlock;
     95    PRTMPNOTIFYREG  pCur;
     96    RTSPINLOCK      hSpinlock;
     97    RTSPINLOCKTMP   Tmp = RTSPINLOCKTMP_INITIALIZER;
    10198
    10299    /*
     
    166163RTDECL(int) RTMpNotificationRegister(PFNRTMPNOTIFICATION pfnCallback, void *pvUser)
    167164{
    168     PRTMPNOTIFYREG pCur;
    169     PRTMPNOTIFYREG pNew;
    170     RTSPINLOCKTMP Tmp;
     165    PRTMPNOTIFYREG  pCur;
     166    PRTMPNOTIFYREG  pNew;
     167    RTSPINLOCKTMP   Tmp = RTSPINLOCKTMP_INITIALIZER;
    171168
    172169    /*
     
    234231RTDECL(int) RTMpNotificationDeregister(PFNRTMPNOTIFICATION pfnCallback, void *pvUser)
    235232{
    236     PRTMPNOTIFYREG pPrev;
    237     PRTMPNOTIFYREG pCur;
    238     RTSPINLOCKTMP Tmp;
     233    PRTMPNOTIFYREG  pPrev;
     234    PRTMPNOTIFYREG  pCur;
     235    RTSPINLOCKTMP   Tmp = RTSPINLOCKTMP_INITIALIZER;
    239236
    240237    /*
     
    284281int rtR0MpNotificationInit(void)
    285282{
    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();
    291287        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;
    301292    }
    302293    return rc;
     
    306297void rtR0MpNotificationTerm(void)
    307298{
    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  
    8282 * make use of this to avoid having restart at the list head after each callback. */
    8383static 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;
    8784
    8885
     
    9289{
    9390    PRTPOWERNOTIFYREG pCur;
    94     RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER;
    95     RTSPINLOCK hSpinlock;
     91    RTSPINLOCK        hSpinlock;
     92    RTSPINLOCKTMP     Tmp = RTSPINLOCKTMP_INITIALIZER;
    9693
    9794    /*
     
    162159RTDECL(int) RTPowerNotificationRegister(PFNRTPOWERNOTIFICATION pfnCallback, void *pvUser)
    163160{
    164     PRTPOWERNOTIFYREG pCur;
    165     PRTPOWERNOTIFYREG pNew;
    166     RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER;
     161    PRTPOWERNOTIFYREG   pCur;
     162    PRTPOWERNOTIFYREG   pNew;
     163    RTSPINLOCKTMP       Tmp = RTSPINLOCKTMP_INITIALIZER;
    167164
    168165    /*
     
    230227RTDECL(int) RTPowerNotificationDeregister(PFNRTPOWERNOTIFICATION pfnCallback, void *pvUser)
    231228{
    232     PRTPOWERNOTIFYREG pPrev;
    233     PRTPOWERNOTIFYREG pCur;
    234     RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER;
     229    PRTPOWERNOTIFYREG   pPrev;
     230    PRTPOWERNOTIFYREG   pCur;
     231    RTSPINLOCKTMP       Tmp = RTSPINLOCKTMP_INITIALIZER;
    235232
    236233    /*
     
    280277int rtR0PowerNotificationInit(void)
    281278{
    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;
    291284#if 0
    292             RTSpinlockDestroy(g_hRTPowerNotifySpinLock);
    293             g_hRTPowerNotifySpinLock = NIL_RTSPINLOCK;
     285        RTSpinlockDestroy(g_hRTPowerNotifySpinLock);
     286        g_hRTPowerNotifySpinLock = NIL_RTSPINLOCK;
    294287#endif
    295         }
    296         ASMAtomicDecU32(&g_cRTPowerUsers);
    297288    }
    298289    return rc;
     
    302293void rtR0PowerNotificationTerm(void)
    303294{
    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.

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