Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 99b1146

Browse files
Remove unused step logic from PALCommonCleanup.
1 parent 1a729f8 commit 99b1146

File tree

4 files changed

+26
-130
lines changed

4 files changed

+26
-130
lines changed

src/pal/src/include/pal/init.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,18 @@ Utility function to force PAL to shutdown state
3838
--*/
3939
void PALShutdown( void );
4040

41-
typedef enum
42-
{
43-
PALCLEANUP_STEP_ONE, /* enum MUST start from 0 */
44-
PALCLEANUP_STEP_TWO,
45-
PALCLEANUP_ALL_STEPS,
46-
PALCLEANUP_STEP_INVALID /* This const MUST be the last entry
47-
in the enum */
48-
} PALCLEANUP_STEP;
49-
5041
/*++
5142
Function:
5243
PALCommonCleanup
5344
5445
Utility function to free any resource used by the PAL.
5546
5647
Parameters :
57-
step: selects the desired cleanup step
5848
full_cleanup: TRUE: cleanup only what's needed and leave the rest
5949
to the OS process cleanup
6050
FALSE: full cleanup
6151
--*/
62-
void PALCommonCleanup( PALCLEANUP_STEP step, BOOL full_cleanup );
52+
void PALCommonCleanup( BOOL full_cleanup );
6353

6454
extern Volatile<INT> init_count;
6555

src/pal/src/init/pal.cpp

Lines changed: 16 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -754,128 +754,35 @@ Parameters :
754754
TRUE: full cleanup
755755
--*/
756756
void
757-
PALCommonCleanup(PALCLEANUP_STEP step, BOOL full_cleanup)
757+
PALCommonCleanup(BOOL full_cleanup)
758758
{
759759
CPalThread *pThread = InternalGetCurrentThread();
760-
static int step_done[PALCLEANUP_STEP_INVALID] = { 0 };
760+
static bool done = false;
761761

762-
switch (step)
762+
if (!done)
763763
{
764-
case PALCLEANUP_ALL_STEPS:
765-
case PALCLEANUP_STEP_ONE:
766-
/* Note: in order to work correctly, this step should be executed with
767-
init_count > 0
768-
*/
769-
if (!step_done[PALCLEANUP_STEP_ONE])
770-
{
771-
step_done[PALCLEANUP_STEP_ONE] = 1;
764+
done = true;
772765

773-
PALSetShutdownIntent();
766+
PALSetShutdownIntent();
774767

775-
//
776-
// Let the synchronization manager know we're about to shutdown
777-
//
768+
//
769+
// Let the synchronization manager know we're about to shutdown
770+
//
778771

779-
CPalSynchMgrController::PrepareForShutdown();
772+
CPalSynchMgrController::PrepareForShutdown();
780773

781774
#ifdef _DEBUG
782-
PROCDumpThreadList();
775+
PROCDumpThreadList();
783776
#endif
784777

785-
TRACE("About to suspend every other thread\n");
778+
TRACE("About to suspend every other thread\n");
786779

787-
/* prevent other threads from acquiring signaled objects */
788-
PROCCondemnOtherThreads();
789-
/* prevent other threads from using services we're shutting down */
790-
PROCSuspendOtherThreads();
791-
792-
TRACE("Every other thread suspended until exit\n");
793-
}
794-
795-
/* Fall down for PALCLEANUP_ALL_STEPS */
796-
if (PALCLEANUP_ALL_STEPS != step)
797-
break;
798-
799-
case PALCLEANUP_STEP_TWO:
800-
if (!step_done[PALCLEANUP_STEP_TWO])
801-
{
802-
step_done[PALCLEANUP_STEP_TWO] = 1;
803-
804-
/* LOADFreeeModules needs to be called before unitializing the rest
805-
of the PAL since it could result in calling DllMain for loaded
806-
libraries. For the user DllMain, all PAL APIs should still be
807-
functional. */
808-
LOADFreeModules(FALSE);
809-
810-
#ifdef PAL_PERF
811-
PERFDisableProcessProfile();
812-
PERFDisableThreadProfile(FALSE);
813-
PERFTerminate();
814-
#endif
815-
816-
if (full_cleanup)
817-
{
818-
/* close primary handles of standard file objects */
819-
FILECleanupStdHandles();
820-
VIRTUALCleanup();
821-
/* SEH requires information from the process structure to work;
822-
LOADFreeModules requires SEH to be functional when calling DllMain.
823-
Therefore SEHCleanup must go between LOADFreeModules and
824-
PROCCleanupInitialProcess */
825-
SEHCleanup();
826-
PROCCleanupInitialProcess();
827-
}
828-
829-
// Object manager shutdown may cause all CPalThread objects
830-
// to be deleted. Since the CPalThread of the shutdown thread
831-
// needs to be available for reference by the thread suspension unsafe
832-
// operations, the reference of CPalThread is incremented here
833-
// to keep it alive until PAL finishes cleanup.
834-
pThread->AddThreadReference();
835-
836-
//
837-
// Shutdown object manager -- this needs to happen before the
838-
// synch manager shutdown since it will call into the synch
839-
// manager to free object synch data
840-
//
841-
static_cast<CSharedMemoryObjectManager*>(g_pObjectManager)->Shutdown(pThread);
842-
843-
//
844-
// Final synch manager shutdown
845-
//
846-
CPalSynchMgrController::Shutdown(pThread, full_cleanup);
847-
848-
if (full_cleanup)
849-
{
850-
/* It needs to be done after stopping the handle manager, because
851-
the cleanup will delete the critical section which is used
852-
when closing the handle of a file mapping */
853-
MAPCleanup();
854-
// MutexCleanup();
855-
856-
MiscCleanup();
857-
858-
TLSCleanup();
859-
}
860-
861-
// The thread object will no longer be available after the shutdown thread
862-
// releases the thread reference.
863-
g_fThreadDataAvailable = FALSE;
864-
pThread->ReleaseThreadReference();
865-
pthread_setspecific(thObjKey, NULL); // Make sure any TLS entry is removed.
866-
867-
// Since thread object is no longer available here,
868-
// the code path from here should stop using any functions
869-
// that reference thread object.
870-
SHMCleanup();
871-
872-
TRACE("PAL Terminated.\n");
873-
}
874-
break;
780+
/* prevent other threads from acquiring signaled objects */
781+
PROCCondemnOtherThreads();
782+
/* prevent other threads from using services we're shutting down */
783+
PROCSuspendOtherThreads();
875784

876-
default:
877-
ASSERT("Unknown final cleanup step %d", step);
878-
break;
785+
TRACE("Every other thread suspended until exit\n");
879786
}
880787
}
881788

src/pal/src/synchmgr/synchmanager.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,7 +1836,7 @@ namespace CorUnix
18361836
PAL_ERROR CPalSynchronizationManager::Shutdown(
18371837
CPalThread *pthrCurrent,
18381838
bool fFullCleanup)
1839-
{
1839+
{
18401840
PAL_ERROR palErr = NO_ERROR;
18411841
CPalSynchronizationManager * pSynchManager = GetInstance();
18421842

@@ -1845,7 +1845,7 @@ namespace CorUnix
18451845
_ASSERT_MSG((LONG)SynchMgrStatusRunning != s_lInitStatus,
18461846
"Synchronization Manager: Shutdown called with no "
18471847
"prior PrepareForShutdown call");
1848-
1848+
18491849
ERROR("Unexpected initialization status found "
18501850
"in Shutdown [expected=%d current=%d]\n",
18511851
(int)SynchMgrStatusShuttingDown, s_lInitStatus.Load());
@@ -1865,14 +1865,14 @@ namespace CorUnix
18651865
pSynchManager->m_cacheThreadApcInfoNodes.Flush(pthrCurrent);
18661866
pSynchManager->m_cacheOwnedObjectsListNodes.Flush(pthrCurrent);
18671867

1868-
InternalDeleteCriticalSection(&s_csSynchProcessLock);
1869-
InternalDeleteCriticalSection(&s_csMonitoredProcessesLock);
1868+
InternalDeleteCriticalSection(&s_csSynchProcessLock);
1869+
InternalDeleteCriticalSection(&s_csMonitoredProcessesLock);
18701870
}
1871-
1871+
18721872
s_lInitStatus = (LONG)SynchMgrStatusIdle;
18731873
s_pObjSynchMgr = NULL;
1874-
1875-
S_exit:
1874+
1875+
S_exit:
18761876
return palErr;
18771877
}
18781878

src/pal/src/thread/process.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,10 +1401,9 @@ void PROCCleanupProcess(BOOL bTerminateUnconditionally)
14011401
/* Declare the beginning of shutdown */
14021402
PALSetShutdownIntent();
14031403

1404-
PALCommonCleanup(PALCLEANUP_STEP_ONE, FALSE);
1404+
PALCommonCleanup(FALSE);
14051405

1406-
/* This must be called after PALCommonCleanup(PALCLEANUP_STEP_ONE, ...)
1407-
*/
1406+
/* This must be called after PALCommonCleanup */
14081407
PALShutdown();
14091408
}
14101409

0 commit comments

Comments
 (0)