VirtualBox

Changeset 101957 in vbox for trunk/src


Ignore:
Timestamp:
Nov 8, 2023 10:50:00 AM (16 months ago)
Author:
vboxsync
Message:

libs/xpcom: Convert nsExceptionService.{cpp,h} to IPRT, bugref:10545

Location:
trunk/src/libs/xpcom18a4/xpcom/base
Files:
2 edited

Legend:

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

    r65440 r101957  
    4343#include "prthread.h"
    4444#include "prlock.h"
    45 static const PRUintn BAD_TLS_INDEX = (PRUintn) -1;
    46 
    47 #define CHECK_SERVICE_USE_OK() if (tlsIndex == BAD_TLS_INDEX) return NS_ERROR_NOT_INITIALIZED
    48 #define CHECK_MANAGER_USE_OK() if (!mService || nsExceptionService::tlsIndex == BAD_TLS_INDEX) return NS_ERROR_NOT_INITIALIZED
     45
     46#include <iprt/asm.h>
     47#include <iprt/errcore.h>
     48
     49#define CHECK_SERVICE_USE_OK() if (tlsIndex == NIL_RTTLS) return NS_ERROR_NOT_INITIALIZED
     50#define CHECK_MANAGER_USE_OK() if (!mService || nsExceptionService::tlsIndex == NIL_RTTLS) return NS_ERROR_NOT_INITIALIZED
    4951
    5052// A key for our registered module providers hashtable
     
    7981  nsExceptionService *mService; // not ref-counted
    8082#ifdef NS_DEBUG
    81   static PRInt32 totalInstances;
     83  static volatile uint32_t totalInstances;
    8284#endif
    8385
     
    103105
    104106#ifdef NS_DEBUG
    105 PRInt32 nsExceptionManager::totalInstances = 0;
     107volatile uint32_t nsExceptionManager::totalInstances = 0;
    106108#endif
    107109
     
    125127  /* member initializers and constructor code */
    126128#ifdef NS_DEBUG
    127   PR_AtomicIncrement(&totalInstances);
     129  ASMAtomicIncU32(&totalInstances);
    128130#endif
    129131}
     
    133135  /* destructor code */
    134136#ifdef NS_DEBUG
    135   PR_AtomicDecrement(&totalInstances);
     137  ASMAtomicDecU32(&totalInstances);
    136138#endif // NS_DEBUG
    137139}
     
    164166/* The Exception Service */
    165167
    166 PRUintn nsExceptionService::tlsIndex = BAD_TLS_INDEX;
    167 PRLock *nsExceptionService::lock = nsnull;
     168RTTLS nsExceptionService::tlsIndex = NIL_RTTLS;
     169RTSEMFASTMUTEX nsExceptionService::lock = NIL_RTSEMFASTMUTEX;
    168170nsExceptionManager *nsExceptionService::firstThread = nsnull;
    169171
    170172#ifdef NS_DEBUG
    171 PRInt32 nsExceptionService::totalInstances = 0;
     173volatile uint32_t nsExceptionService::totalInstances = 0;
    172174#endif
    173175
     
    178180{
    179181#ifdef NS_DEBUG
    180   if (PR_AtomicIncrement(&totalInstances)!=1) {
     182  if (ASMAtomicIncU32(&totalInstances)!=1) {
    181183    NS_ERROR("The nsExceptionService is a singleton!");
    182184  }
    183185#endif
    184186  /* member initializers and constructor code */
    185   if (tlsIndex == BAD_TLS_INDEX) {
    186     PRStatus status;
    187     status = PR_NewThreadPrivateIndex( &tlsIndex, ThreadDestruct );
    188     NS_WARN_IF_FALSE(status==0, "ScriptErrorService could not allocate TLS storage.");
    189   }
    190   lock = PR_NewLock();
    191   NS_WARN_IF_FALSE(lock, "Error allocating ExceptionService lock");
     187  if (tlsIndex == NIL_RTTLS) {
     188    int vrc = RTTlsAllocEx( &tlsIndex, ThreadDestruct );
     189    NS_WARN_IF_FALSE(RT_SUCCESS(vrc), "ScriptErrorService could not allocate TLS storage.");
     190  }
     191  int vrc = RTSemFastMutexCreate(&lock);
     192  NS_WARN_IF_FALSE(RT_SUCCESS(vrc), "Error allocating ExceptionService lock");
    192193
    193194  // observe XPCOM shutdown.
     
    201202{
    202203  Shutdown();
    203   if (lock) {
    204     PRLock *tmp = lock;
    205     lock = nsnull;
    206     PR_DestroyLock(tmp);
     204  if (lock != NIL_RTSEMFASTMUTEX) {
     205    RTSEMFASTMUTEX tmp = lock;
     206    lock = NULL;
     207    RTSemFastMutexDestroy(tmp);
    207208  }
    208209  /* destructor code */
    209210#ifdef NS_DEBUG
    210   PR_AtomicDecrement(&totalInstances);
     211  ASMAtomicDecU32(&totalInstances);
    211212#endif
    212213}
    213214
    214215/*static*/
    215 void nsExceptionService::ThreadDestruct( void *data )
    216 {
    217   if (!lock) {
     216DECLCALLBACK(void) nsExceptionService::ThreadDestruct( void *data )
     217{
     218  if (lock == NIL_RTSEMFASTMUTEX) {
    218219    NS_WARNING("nsExceptionService ignoring thread destruction after shutdown");
    219220    return;
     
    225226void nsExceptionService::Shutdown()
    226227{
    227   PRUintn tmp = tlsIndex;
    228   tlsIndex = BAD_TLS_INDEX;
    229   PR_SetThreadPrivate(tmp, nsnull);
     228  RTTLS tmp = tlsIndex;
     229  tlsIndex = NIL_RTTLS;
     230  RTTlsSet(tmp, NULL);
    230231  mProviders.Reset();
    231   if (lock) {
     232  if (lock != NIL_RTSEMFASTMUTEX) {
    232233    DropAllThreads();
    233234  }
     
    268269{
    269270    CHECK_SERVICE_USE_OK();
    270     nsExceptionManager *mgr = (nsExceptionManager *)PR_GetThreadPrivate(tlsIndex);
     271    nsExceptionManager *mgr = (nsExceptionManager *)RTTlsGet(tlsIndex);
    271272    if (mgr == nsnull) {
    272273        // Stick the new exception object in with no reference count.
     
    274275        if (mgr == nsnull)
    275276            return NS_ERROR_OUT_OF_MEMORY;
    276         PR_SetThreadPrivate(tlsIndex, mgr);
     277        RTTlsSet(tlsIndex, mgr);
    277278        // The reference count is held in the thread-list
    278279        AddThread(mgr);
     
    345346/*static*/ void nsExceptionService::AddThread(nsExceptionManager *thread)
    346347{
    347     PR_Lock(lock);
     348    RTSemFastMutexRequest(lock);
    348349    thread->mNextThread = firstThread;
    349350    firstThread = thread;
    350351    NS_ADDREF(thread);
    351     PR_Unlock(lock);
     352    RTSemFastMutexRelease(lock);
    352353}
    353354
     
    370371/*static*/ void nsExceptionService::DropThread(nsExceptionManager *thread)
    371372{
    372     PR_Lock(lock);
     373    RTSemFastMutexRequest(lock);
    373374    DoDropThread(thread);
    374     PR_Unlock(lock);
     375    RTSemFastMutexRelease(lock);
    375376}
    376377
    377378/*static*/ void nsExceptionService::DropAllThreads()
    378379{
    379     PR_Lock(lock);
     380    RTSemFastMutexRequest(lock);
    380381    while (firstThread)
    381382        DoDropThread(firstThread);
    382     PR_Unlock(lock);
    383 }
     383    RTSemFastMutexRelease(lock);
     384}
  • trunk/src/libs/xpcom18a4/xpcom/base/nsExceptionService.h

    r1 r101957  
    4747#include "nsIObserver.h"
    4848
     49#include <iprt/semaphore.h>
     50#include <iprt/thread.h>
     51
    4952class nsExceptionManager;
    5053
     
    7982  /* single lock protects both providers hashtable
    8083     and thread list */
    81   static PRLock* lock;
     84  static RTSEMFASTMUTEX lock;
    8285
    83   static PRUintn tlsIndex;
    84   static void PR_CALLBACK ThreadDestruct( void *data );
     86  static RTTLS tlsIndex;
     87  static DECLCALLBACK(void) ThreadDestruct(void *data);
    8588#ifdef NS_DEBUG
    86   static PRInt32 totalInstances;
     89  static volatile uint32_t totalInstances;
    8790#endif
    8891
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