VirtualBox

Changeset 101975 in vbox for trunk/src/libs/xpcom18a4


Ignore:
Timestamp:
Nov 8, 2023 1:31:55 PM (15 months ago)
Author:
vboxsync
Message:

libs/xpcom/xpcom: Convert some code from using PRLock to IPRT's RTSEMFASTMUTEX locks, bugref:10545

Location:
trunk/src/libs/xpcom18a4/xpcom
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/xpcom/base/nsTraceRefcntImpl.cpp

    r101828 r101975  
    101101#include "prmem.h"
    102102
    103 #include "prlock.h"
    104 
    105 static PRLock* gTraceLock;
    106 
    107 #define LOCK_TRACELOG()   PR_Lock(gTraceLock)
    108 #define UNLOCK_TRACELOG() PR_Unlock(gTraceLock)
     103#include <iprt/assert.h>
     104#include <iprt/errcore.h>
     105#include <iprt/semaphore.h>
     106
     107static RTSEMFASTMUTEX gTraceLock = NIL_RTSEMFASTMUTEX;
     108
     109#define LOCK_TRACELOG()   RTSemFastMutexRequest(gTraceLock)
     110#define UNLOCK_TRACELOG() RTSemFastMutexRelease(gTraceLock)
    109111
    110112static PLHashTable* gBloatView;
     
    828830  }
    829831
    830   gTraceLock = PR_NewLock();
     832  int vrc = RTSemFastMutexCreate(&gTraceLock);
     833  AssertRC(vrc); RT_NOREF(vrc);
    831834}
    832835
  • trunk/src/libs/xpcom18a4/xpcom/ds/nsBaseHashtable.h

    r40023 r101975  
    4040
    4141#include "nsTHashtable.h"
    42 #include "prlock.h"
    4342#include "nsDebug.h"
     43
     44#include <iprt/assert.h>
     45#include <iprt/errcore.h>
     46#include <iprt/semaphore.h>
    4447
    4548template<class KeyClass,class DataType,class UserDataType>
     
    291294
    292295protected:
    293   PRLock* mLock;
     296  RTSEMFASTMUTEX mLock;
    294297};
    295298 
     
    358361nsBaseHashtableMT<KeyClass,DataType,UserDataType>::~nsBaseHashtableMT()
    359362{
    360   if (this->mLock)
    361     PR_DestroyLock(this->mLock);
     363  if (this->mLock != NIL_RTSEMFASTMUTEX)
     364  {
     365    RTSemFastMutexDestroy(this->mLock);
     366    this->mLock = NIL_RTSEMFASTMUTEX;
     367  }
    362368}
    363369
     
    369375    return PR_FALSE;
    370376
    371   this->mLock = PR_NewLock();
    372   NS_WARN_IF_FALSE(this->mLock, "Error creating lock during nsBaseHashtableL::Init()");
    373 
    374   return (this->mLock != nsnull);
     377  this->mLock = NIL_RTSEMFASTMUTEX;
     378  int vrc = RTSemFastMutexCreate(&this->mLock);
     379  NS_WARN_IF_FALSE(RT_SUCCESS(vrc), "Error creating lock during nsBaseHashtableL::Init()");
     380
     381  return (this->mLock != NIL_RTSEMFASTMUTEX);
    375382}
    376383
     
    379386nsBaseHashtableMT<KeyClass,DataType,UserDataType>::Count() const
    380387{
    381   PR_Lock(this->mLock);
     388  RTSemFastMutexRequest(this->mLock);
    382389  PRUint32 count = nsTHashtable<EntryType>::Count();
    383   PR_Unlock(this->mLock);
     390  RTSemFastMutexRelease(this->mLock);
    384391
    385392  return count;
     
    391398                                                           UserDataType* pData) const
    392399{
    393   PR_Lock(this->mLock);
     400  RTSemFastMutexRequest(this->mLock);
    394401  PRBool res =
    395402    nsBaseHashtable<KeyClass,DataType,UserDataType>::Get(aKey, pData);
    396   PR_Unlock(this->mLock);
     403  RTSemFastMutexRelease(this->mLock);
    397404
    398405  return res;
     
    404411                                                           UserDataType aData)
    405412{
    406   PR_Lock(this->mLock);
     413  RTSemFastMutexRequest(this->mLock);
    407414  PRBool res =
    408415    nsBaseHashtable<KeyClass,DataType,UserDataType>::Put(aKey, aData);
    409   PR_Unlock(this->mLock);
     416  RTSemFastMutexRelease(this->mLock);
    410417
    411418  return res;
     
    416423nsBaseHashtableMT<KeyClass,DataType,UserDataType>::Remove(KeyType aKey)
    417424{
    418   PR_Lock(this->mLock);
     425  RTSemFastMutexRequest(this->mLock);
    419426  nsBaseHashtable<KeyClass,DataType,UserDataType>::Remove(aKey);
    420   PR_Unlock(this->mLock);
     427  RTSemFastMutexRelease(this->mLock);
    421428}
    422429
     
    426433  (EnumReadFunction fEnumCall, void* userArg) const
    427434{
    428   PR_Lock(this->mLock);
     435  RTSemFastMutexRequest(this->mLock);
    429436  PRUint32 count =
    430437    nsBaseHashtable<KeyClass,DataType,UserDataType>::EnumerateRead(fEnumCall, userArg);
    431   PR_Unlock(this->mLock);
     438  RTSemFastMutexRelease(this->mLock);
    432439
    433440  return count;
     
    439446  (EnumFunction fEnumCall, void* userArg)
    440447{
    441   PR_Lock(this->mLock);
     448  RTSemFastMutexRequest(this->mLock);
    442449  PRUint32 count =
    443450    nsBaseHashtable<KeyClass,DataType,UserDataType>::Enumerate(fEnumCall, userArg);
    444   PR_Unlock(this->mLock);
     451  RTSemFastMutexRelease(this->mLock);
    445452
    446453  return count;
     
    451458nsBaseHashtableMT<KeyClass,DataType,UserDataType>::Clear()
    452459{
    453   PR_Lock(this->mLock);
     460  RTSemFastMutexRequest(this->mLock);
    454461  nsBaseHashtable<KeyClass,DataType,UserDataType>::Clear();
    455   PR_Unlock(this->mLock);
     462  RTSemFastMutexRelease(this->mLock);
    456463}
    457464
  • trunk/src/libs/xpcom18a4/xpcom/ds/nsClassHashtable.h

    r40023 r101975  
    124124nsClassHashtableMT<KeyClass,T>::Get(KeyType aKey, T** retVal) const
    125125{
    126   PR_Lock(this->mLock);
     126  RTSemFastMutexRequest(this->mLock);
    127127
    128128  typename nsBaseHashtableMT<KeyClass,nsAutoPtr<T>,T*>::EntryType* ent =
     
    134134      *retVal = ent->mData;
    135135
    136     PR_Unlock(this->mLock);
     136    RTSemFastMutexRelease(this->mLock);
    137137
    138138    return PR_TRUE;
     
    142142    *retVal = nsnull;
    143143
    144   PR_Unlock(this->mLock);
     144  RTSemFastMutexRelease(this->mLock);
    145145
    146146  return PR_FALSE;
  • trunk/src/libs/xpcom18a4/xpcom/ds/nsHashtable.cpp

    r1 r101975  
    5656#include "nsCRT.h"
    5757
     58#include <iprt/assert.h>
     59#include <iprt/errcore.h>
     60
    5861struct HTEntry : PLDHashEntryHdr
    5962{
     
    169172    if (!result)
    170173        mHashtable.ops = nsnull;
    171    
    172     if (threadSafe) {
    173         mLock = PR_NewLock();
    174         if (mLock == NULL) {
    175             // Cannot create a lock. If running on a multiprocessing system
    176             // we are sure to die.
    177             PR_ASSERT(mLock != NULL);
    178         }
     174
     175    mLock = NIL_RTSEMFASTMUTEX;
     176    if (threadSafe)
     177    {
     178        int vrc = RTSemFastMutexCreate(&mLock);
     179        // Cannot create a lock. If running on a multiprocessing system
     180        // we are sure to die.
     181        AssertReleaseRC(vrc);
    179182    }
    180183}
     
    185188    if (mHashtable.ops)
    186189        PL_DHashTableFinish(&mHashtable);
    187     if (mLock) PR_DestroyLock(mLock);
     190    if (mLock != NIL_RTSEMFASTMUTEX)
     191    {
     192        int vrc = RTSemFastMutexDestroy(mLock);
     193        AssertRC(vrc);
     194    }
    188195}
    189196
    190197PRBool nsHashtable::Exists(nsHashKey *aKey)
    191198{
    192     if (mLock) PR_Lock(mLock);
     199    if (mLock) RTSemFastMutexRequest(mLock);
    193200
    194201    if (!mHashtable.ops)
     
    200207    PRBool exists = PL_DHASH_ENTRY_IS_BUSY(entry);
    201208   
    202     if (mLock) PR_Unlock(mLock);
     209    if (mLock) RTSemFastMutexRelease(mLock);
    203210
    204211    return exists;
     
    211218    if (!mHashtable.ops) return nsnull;
    212219   
    213     if (mLock) PR_Lock(mLock);
     220    if (mLock) RTSemFastMutexRequest(mLock);
    214221
    215222    // shouldn't be adding an item during enumeration
     
    232239    }
    233240
    234     if (mLock) PR_Unlock(mLock);
     241    if (mLock) RTSemFastMutexRelease(mLock);
    235242
    236243    return res;
     
    241248    if (!mHashtable.ops) return nsnull;
    242249   
    243     if (mLock) PR_Lock(mLock);
     250    if (mLock) RTSemFastMutexRequest(mLock);
    244251
    245252    HTEntry* entry =
     
    248255    void *ret = PL_DHASH_ENTRY_IS_BUSY(entry) ? entry->value : nsnull;
    249256   
    250     if (mLock) PR_Unlock(mLock);
     257    if (mLock) RTSemFastMutexRelease(mLock);
    251258
    252259    return ret;
     
    257264    if (!mHashtable.ops) return nsnull;
    258265   
    259     if (mLock) PR_Lock(mLock);
     266    if (mLock) RTSemFastMutexRequest(mLock);
    260267
    261268    // shouldn't be adding an item during enumeration
     
    278285    }
    279286
    280     if (mLock) PR_Unlock(mLock);
     287    if (mLock) RTSemFastMutexRelease(mLock);
    281288
    282289    return res;
     
    367374    nsresult rv = aStream->ReadBoolean(&threadSafe);
    368375    if (NS_SUCCEEDED(rv)) {
    369         if (threadSafe) {
    370             mLock = PR_NewLock();
    371             if (!mLock)
     376        if (threadSafe)
     377        {
     378            int vrc = RTSemFastMutexCreate(&mLock);
     379            if (RT_FAILURE(vrc))
    372380                rv = NS_ERROR_OUT_OF_MEMORY;
    373381        }
  • trunk/src/libs/xpcom18a4/xpcom/ds/nsHashtable.h

    r1 r101975  
    5555
    5656#include "pldhash.h"
    57 #include "prlock.h"
    5857#include "nscore.h"
    5958#include "nsString.h"
    6059#include "nsISupportsBase.h"
    6160#include "nsTraceRefcnt.h"
     61
     62#include <iprt/semaphore.h>
    6263
    6364class nsIObjectInputStream;
     
    135136  protected:
    136137    // members 
    137     PRLock*         mLock;
     138    RTSEMFASTMUTEX  mLock;
    138139    PLDHashTable    mHashtable;
    139140    PRBool          mEnumerating;
  • trunk/src/libs/xpcom18a4/xpcom/ds/nsInterfaceHashtable.h

    r40023 r101975  
    165165  (KeyType aKey, UserDataType* pInterface) const
    166166{
    167   PR_Lock(this->mLock);
     167  RTSemFastMutexRequest(this->mLock);
    168168
    169169  typename nsBaseHashtableMT<KeyClass, nsCOMPtr<Interface>, Interface*>::EntryType* ent =
     
    179179    }
    180180
    181     PR_Unlock(this->mLock);
     181    RTSemFastMutexRelease(this->mLock);
    182182
    183183    return PR_TRUE;
     
    189189    *pInterface = nsnull;
    190190
    191   PR_Unlock(this->mLock);
     191  RTSemFastMutexRelease(this->mLock);
    192192
    193193  return PR_FALSE;
Note: See TracChangeset for help on using the changeset viewer.

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