diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index 77b641a5059232..3cca5f86098e91 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -191,6 +191,7 @@ PAL_IsDebuggerPresent(); #define PAL_INITIALIZE_ENSURE_STACK_SIZE 0x20 #define PAL_INITIALIZE_REGISTER_SIGNALS 0x40 #define PAL_INITIALIZE_REGISTER_ACTIVATION_SIGNAL 0x80 +#define PAL_INITIALIZE_FLUSH_PROCES_WRITE_BUFFERS 0x100 // PAL_Initialize() flags #define PAL_INITIALIZE (PAL_INITIALIZE_SYNC_THREAD | \ @@ -206,7 +207,8 @@ PAL_IsDebuggerPresent(); PAL_INITIALIZE_DEBUGGER_EXCEPTIONS | \ PAL_INITIALIZE_ENSURE_STACK_SIZE | \ PAL_INITIALIZE_REGISTER_SIGNALS | \ - PAL_INITIALIZE_REGISTER_ACTIVATION_SIGNAL) + PAL_INITIALIZE_REGISTER_ACTIVATION_SIGNAL | \ + PAL_INITIALIZE_FLUSH_PROCES_WRITE_BUFFERS) typedef DWORD (PALAPI_NOEXPORT *PTHREAD_START_ROUTINE)(LPVOID lpThreadParameter); typedef PTHREAD_START_ROUTINE LPTHREAD_START_ROUTINE; diff --git a/src/coreclr/pal/src/init/pal.cpp b/src/coreclr/pal/src/init/pal.cpp index 7a8fc556724c1f..ab49e4e2464a8a 100644 --- a/src/coreclr/pal/src/init/pal.cpp +++ b/src/coreclr/pal/src/init/pal.cpp @@ -382,6 +382,16 @@ Initialize( goto CLEANUP0a; } + if (flags & PAL_INITIALIZE_FLUSH_PROCES_WRITE_BUFFERS) + { + // Initialize before first thread is created for faster load on Linux + if (!InitializeFlushProcessWriteBuffers()) + { + palError = ERROR_PALINIT_INITIALIZE_FLUSH_PROCESS_WRITE_BUFFERS; + goto CLEANUP0a; + } + } + // The gSharedFilesPath is allocated dynamically so its destructor does not get // called unexpectedly during cleanup gSharedFilesPath = InternalNew(); @@ -787,11 +797,6 @@ PAL_InitializeCoreCLR(const char *szExePath, BOOL runningInExe) return ERROR_PALINIT_PROCABORT_INITIALIZE; } - if (!InitializeFlushProcessWriteBuffers()) - { - return ERROR_PALINIT_INITIALIZE_FLUSH_PROCESS_WRITE_BUFFERS; - } - return ERROR_SUCCESS; }