- Timestamp:
- Nov 8, 2023 10:50:00 AM (16 months ago)
- Location:
- trunk/src/libs/xpcom18a4/xpcom/base
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/xpcom/base/nsExceptionService.cpp
r65440 r101957 43 43 #include "prthread.h" 44 44 #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 49 51 50 52 // A key for our registered module providers hashtable … … 79 81 nsExceptionService *mService; // not ref-counted 80 82 #ifdef NS_DEBUG 81 static PRInt32totalInstances;83 static volatile uint32_t totalInstances; 82 84 #endif 83 85 … … 103 105 104 106 #ifdef NS_DEBUG 105 PRInt32nsExceptionManager::totalInstances = 0;107 volatile uint32_t nsExceptionManager::totalInstances = 0; 106 108 #endif 107 109 … … 125 127 /* member initializers and constructor code */ 126 128 #ifdef NS_DEBUG 127 PR_AtomicIncrement(&totalInstances);129 ASMAtomicIncU32(&totalInstances); 128 130 #endif 129 131 } … … 133 135 /* destructor code */ 134 136 #ifdef NS_DEBUG 135 PR_AtomicDecrement(&totalInstances);137 ASMAtomicDecU32(&totalInstances); 136 138 #endif // NS_DEBUG 137 139 } … … 164 166 /* The Exception Service */ 165 167 166 PRUintn nsExceptionService::tlsIndex = BAD_TLS_INDEX;167 PRLock *nsExceptionService::lock = nsnull;168 RTTLS nsExceptionService::tlsIndex = NIL_RTTLS; 169 RTSEMFASTMUTEX nsExceptionService::lock = NIL_RTSEMFASTMUTEX; 168 170 nsExceptionManager *nsExceptionService::firstThread = nsnull; 169 171 170 172 #ifdef NS_DEBUG 171 PRInt32nsExceptionService::totalInstances = 0;173 volatile uint32_t nsExceptionService::totalInstances = 0; 172 174 #endif 173 175 … … 178 180 { 179 181 #ifdef NS_DEBUG 180 if ( PR_AtomicIncrement(&totalInstances)!=1) {182 if (ASMAtomicIncU32(&totalInstances)!=1) { 181 183 NS_ERROR("The nsExceptionService is a singleton!"); 182 184 } 183 185 #endif 184 186 /* 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"); 192 193 193 194 // observe XPCOM shutdown. … … 201 202 { 202 203 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); 207 208 } 208 209 /* destructor code */ 209 210 #ifdef NS_DEBUG 210 PR_AtomicDecrement(&totalInstances);211 ASMAtomicDecU32(&totalInstances); 211 212 #endif 212 213 } 213 214 214 215 /*static*/ 215 voidnsExceptionService::ThreadDestruct( void *data )216 { 217 if ( !lock) {216 DECLCALLBACK(void) nsExceptionService::ThreadDestruct( void *data ) 217 { 218 if (lock == NIL_RTSEMFASTMUTEX) { 218 219 NS_WARNING("nsExceptionService ignoring thread destruction after shutdown"); 219 220 return; … … 225 226 void nsExceptionService::Shutdown() 226 227 { 227 PRUintntmp = tlsIndex;228 tlsIndex = BAD_TLS_INDEX;229 PR_SetThreadPrivate(tmp, nsnull);228 RTTLS tmp = tlsIndex; 229 tlsIndex = NIL_RTTLS; 230 RTTlsSet(tmp, NULL); 230 231 mProviders.Reset(); 231 if (lock ) {232 if (lock != NIL_RTSEMFASTMUTEX) { 232 233 DropAllThreads(); 233 234 } … … 268 269 { 269 270 CHECK_SERVICE_USE_OK(); 270 nsExceptionManager *mgr = (nsExceptionManager *) PR_GetThreadPrivate(tlsIndex);271 nsExceptionManager *mgr = (nsExceptionManager *)RTTlsGet(tlsIndex); 271 272 if (mgr == nsnull) { 272 273 // Stick the new exception object in with no reference count. … … 274 275 if (mgr == nsnull) 275 276 return NS_ERROR_OUT_OF_MEMORY; 276 PR_SetThreadPrivate(tlsIndex, mgr);277 RTTlsSet(tlsIndex, mgr); 277 278 // The reference count is held in the thread-list 278 279 AddThread(mgr); … … 345 346 /*static*/ void nsExceptionService::AddThread(nsExceptionManager *thread) 346 347 { 347 PR_Lock(lock);348 RTSemFastMutexRequest(lock); 348 349 thread->mNextThread = firstThread; 349 350 firstThread = thread; 350 351 NS_ADDREF(thread); 351 PR_Unlock(lock);352 RTSemFastMutexRelease(lock); 352 353 } 353 354 … … 370 371 /*static*/ void nsExceptionService::DropThread(nsExceptionManager *thread) 371 372 { 372 PR_Lock(lock);373 RTSemFastMutexRequest(lock); 373 374 DoDropThread(thread); 374 PR_Unlock(lock);375 RTSemFastMutexRelease(lock); 375 376 } 376 377 377 378 /*static*/ void nsExceptionService::DropAllThreads() 378 379 { 379 PR_Lock(lock);380 RTSemFastMutexRequest(lock); 380 381 while (firstThread) 381 382 DoDropThread(firstThread); 382 PR_Unlock(lock);383 } 383 RTSemFastMutexRelease(lock); 384 } -
trunk/src/libs/xpcom18a4/xpcom/base/nsExceptionService.h
r1 r101957 47 47 #include "nsIObserver.h" 48 48 49 #include <iprt/semaphore.h> 50 #include <iprt/thread.h> 51 49 52 class nsExceptionManager; 50 53 … … 79 82 /* single lock protects both providers hashtable 80 83 and thread list */ 81 static PRLock*lock;84 static RTSEMFASTMUTEX lock; 82 85 83 static PRUintntlsIndex;84 static void PR_CALLBACK ThreadDestruct( void *data);86 static RTTLS tlsIndex; 87 static DECLCALLBACK(void) ThreadDestruct(void *data); 85 88 #ifdef NS_DEBUG 86 static PRInt32totalInstances;89 static volatile uint32_t totalInstances; 87 90 #endif 88 91
Note:
See TracChangeset
for help on using the changeset viewer.