@@ -754,128 +754,35 @@ Parameters :
754
754
TRUE: full cleanup
755
755
--*/
756
756
void
757
- PALCommonCleanup (PALCLEANUP_STEP step, BOOL full_cleanup)
757
+ PALCommonCleanup (BOOL full_cleanup)
758
758
{
759
759
CPalThread *pThread = InternalGetCurrentThread ();
760
- static int step_done[PALCLEANUP_STEP_INVALID] = { 0 } ;
760
+ static bool done = false ;
761
761
762
- switch (step )
762
+ if (!done )
763
763
{
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 ;
772
765
773
- PALSetShutdownIntent ();
766
+ PALSetShutdownIntent ();
774
767
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
+ //
778
771
779
- CPalSynchMgrController::PrepareForShutdown ();
772
+ CPalSynchMgrController::PrepareForShutdown ();
780
773
781
774
#ifdef _DEBUG
782
- PROCDumpThreadList ();
775
+ PROCDumpThreadList ();
783
776
#endif
784
777
785
- TRACE (" About to suspend every other thread\n " );
778
+ TRACE (" About to suspend every other thread\n " );
786
779
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 ();
875
784
876
- default :
877
- ASSERT (" Unknown final cleanup step %d" , step);
878
- break ;
785
+ TRACE (" Every other thread suspended until exit\n " );
879
786
}
880
787
}
881
788
0 commit comments