Changeset 101795 in vbox for trunk/src/libs/xpcom18a4/nsprpub
- Timestamp:
- Nov 4, 2023 9:33:05 PM (15 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/nsprpub/pr/src/misc/prinit.c
r101793 r101795 59 59 PRFileDesc *_pr_stderr; 60 60 61 #if !defined(_PR_PTHREADS) && !defined(_PR_BTHREADS)62 63 PRCList _pr_active_local_threadQ =64 PR_INIT_STATIC_CLIST(&_pr_active_local_threadQ);65 PRCList _pr_active_global_threadQ =66 PR_INIT_STATIC_CLIST(&_pr_active_global_threadQ);67 68 _MDLock _pr_cpuLock; /* lock for the CPU Q */69 PRCList _pr_cpuQ = PR_INIT_STATIC_CLIST(&_pr_cpuQ);70 71 PRUint32 _pr_utid;72 73 PRInt32 _pr_userActive;74 PRInt32 _pr_systemActive;75 PRUintn _pr_maxPTDs;76 77 #ifdef _PR_LOCAL_THREADS_ONLY78 79 struct _PRCPU *_pr_currentCPU;80 PRThread *_pr_currentThread;81 PRThread *_pr_lastThread;82 PRInt32 _pr_intsOff;83 84 #endif /* _PR_LOCAL_THREADS_ONLY */85 86 /* Lock protecting all "termination" condition variables of all threads */87 PRLock *_pr_terminationCVLock;88 89 #endif /* !defined(_PR_PTHREADS) */90 91 61 PRLock *_pr_sleeplock; /* used in PR_Sleep(), classic and pthreads */ 92 62 … … 295 265 return rv; 296 266 } /* PR_Initialize */ 297 298 /*299 *-----------------------------------------------------------------------300 *301 * _PR_CleanupBeforeExit --302 *303 * Perform the cleanup work before exiting the process.304 * We first do the cleanup generic to all platforms. Then305 * we call _PR_MD_CLEANUP_BEFORE_EXIT(), where platform-dependent306 * cleanup is done. This function is used by PR_Cleanup().307 *308 * See also: PR_Cleanup().309 *310 *-----------------------------------------------------------------------311 */312 #if defined(_PR_PTHREADS) || defined(_PR_BTHREADS)313 /* see ptthread.c */314 #else315 static void316 _PR_CleanupBeforeExit(void)317 {318 /*319 Do not make any calls here other than to destroy resources. For example,320 do not make any calls that eventually may end up in PR_Lock. Because the321 thread is destroyed, can not access current thread any more.322 */323 _PR_CleanupTPD();324 if (_pr_terminationCVLock)325 /*326 * In light of the comment above, this looks real suspicious.327 * I'd go so far as to say it's just a problem waiting to happen.328 */329 PR_DestroyLock(_pr_terminationCVLock);330 331 _PR_MD_CLEANUP_BEFORE_EXIT();332 }333 #endif /* defined(_PR_PTHREADS) */334 335 /*336 *----------------------------------------------------------------------337 *338 * PR_Cleanup --339 *340 * Perform a graceful shutdown of the NSPR runtime. PR_Cleanup() may341 * only be called from the primordial thread, typically at the342 * end of the main() function. It returns when it has completed343 * its platform-dependent duty and the process must not make any other344 * NSPR library calls prior to exiting from main().345 *346 * PR_Cleanup() first blocks the primordial thread until all the347 * other user (non-system) threads, if any, have terminated.348 * Then it performs cleanup in preparation for exiting the process.349 * PR_Cleanup() does not exit the primordial thread (which would350 * in turn exit the process).351 *352 * PR_Cleanup() only responds when it is called by the primordial353 * thread. Calls by any other thread are silently ignored.354 *355 * See also: PR_ExitProcess()356 *357 *----------------------------------------------------------------------358 */359 #if defined(_PR_PTHREADS) || defined(_PR_BTHREADS)360 /* see ptthread.c */361 #else362 363 PR_IMPLEMENT(PRStatus) PR_Cleanup()364 {365 PRThread *me = PR_GetCurrentThread();366 PR_ASSERT((NULL != me) && (me->flags & _PR_PRIMORDIAL));367 if ((NULL != me) && (me->flags & _PR_PRIMORDIAL))368 {369 PR_LOG(_pr_thread_lm, PR_LOG_MIN, ("PR_Cleanup: shutting down NSPR"));370 371 /*372 * No more recycling of threads373 */374 _pr_recycleThreads = 0;375 376 /*377 * Wait for all other user (non-system/daemon) threads378 * to terminate.379 */380 PR_Lock(_pr_activeLock);381 while (_pr_userActive > _pr_primordialExitCount) {382 PR_WaitCondVar(_pr_primordialExitCVar, PR_INTERVAL_NO_TIMEOUT);383 }384 PR_Unlock(_pr_activeLock);385 386 #ifdef IRIX387 _PR_MD_PRE_CLEANUP(me);388 /*389 * The primordial thread must now be running on the primordial cpu390 */391 PR_ASSERT((_PR_IS_NATIVE_THREAD(me)) || (me->cpu->id == 0));392 #endif393 394 _PR_CleanupDtoa();395 _PR_CleanupCallOnce();396 _PR_ShutdownLinker();397 /* Release the primordial thread's private data, etc. */398 _PR_CleanupThread(me);399 400 _PR_MD_STOP_INTERRUPTS();401 402 PR_LOG(_pr_thread_lm, PR_LOG_MIN,403 ("PR_Cleanup: clean up before destroying thread"));404 _PR_LogCleanup();405 406 /*407 * This part should look like the end of _PR_NativeRunThread408 * and _PR_UserRunThread.409 */410 if (_PR_IS_NATIVE_THREAD(me)) {411 _PR_MD_EXIT_THREAD(me);412 _PR_NativeDestroyThread(me);413 } else {414 _PR_UserDestroyThread(me);415 PR_DELETE(me->stack);416 PR_DELETE(me);417 }418 419 /*420 * XXX: We are freeing the heap memory here so that Purify won't421 * complain, but we should also free other kinds of resources422 * that are allocated by the _PR_InitXXX() functions.423 * Ideally, for each _PR_InitXXX(), there should be a corresponding424 * _PR_XXXCleanup() that we can call here.425 */426 _PR_CleanupIO();427 #ifdef WINNT428 _PR_CleanupCPUs();429 #endif430 _PR_CleanupThreads();431 PR_DestroyLock(_pr_sleeplock);432 _pr_sleeplock = NULL;433 _PR_CleanupLayerCache();434 _PR_CleanupEnv();435 _PR_CleanupStacks();436 _PR_CleanupBeforeExit();437 _pr_initialized = PR_FALSE;438 return PR_SUCCESS;439 }440 return PR_FAILURE;441 }442 #endif /* defined(_PR_PTHREADS) */443 444 /*445 *------------------------------------------------------------------------446 * PR_ProcessExit --447 *448 * Cause an immediate, nongraceful, forced termination of the process.449 * It takes a PRIntn argument, which is the exit status code of the450 * process.451 *452 * See also: PR_Cleanup()453 *454 *------------------------------------------------------------------------455 */456 457 #if defined(_PR_PTHREADS) || defined(_PR_BTHREADS)458 /* see ptthread.c */459 #else460 PR_IMPLEMENT(void) PR_ProcessExit(PRIntn status)461 {462 _PR_MD_EXIT(status);463 }464 465 #endif /* defined(_PR_PTHREADS) */466 267 467 268 PR_IMPLEMENT(PRProcessAttr *)
Note:
See TracChangeset
for help on using the changeset viewer.