Introduce preloadThread for launcher (#451)
author이형주/Common Platform Lab(SR)/삼성전자 <leee.lee@samsung.com>
Mon, 5 Dec 2022 00:09:07 +0000 (09:09 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 5 Dec 2022 00:09:07 +0000 (09:09 +0900)
* Introduce preloadThread for launcher

NativeLauncher/launcher/lib/core_runtime.cc

index 5f1be89..25b59a0 100644 (file)
@@ -33,6 +33,7 @@
 #include <sys/wait.h>
 #include <unistd.h>
 #include <linux/limits.h>
+#include <pthread.h>
 
 #include <storage.h>
 #include <vconf.h>
@@ -267,6 +268,15 @@ void preload()
        pluginPreload();
 }
 
+static pthread_t preloadThreadId = 0;
+static void* preloadThread(void* arg)
+{
+       _INFO("PreloadThread START\n");
+       preload();
+       _INFO("PreloadThread END\n");
+       pthread_exit(NULL);
+}
+
 bool initializeCoreClr(PathManager* pm, const std::string& tpa)
 {
        bool ncdbStartupHook = isNCDBStartupHookProvided();
@@ -354,10 +364,10 @@ int CoreRuntime::initialize(const char* appType, LaunchMode launchMode)
        // See https://github.com/dotnet/coreclr/issues/6698
        //
        // libunwind use following methods to unwind stack frame.
-       // UNW_ARM_METHOD_ALL          0xFF
-       // UNW_ARM_METHOD_DWARF        0x01
-       // UNW_ARM_METHOD_FRAME        0x02
-       // UNW_ARM_METHOD_EXIDX        0x04
+       // UNW_ARM_METHOD_ALL           0xFF
+       // UNW_ARM_METHOD_DWARF         0x01
+       // UNW_ARM_METHOD_FRAME         0x02
+       // UNW_ARM_METHOD_EXIDX         0x04
        putenv(const_cast<char *>("UNW_ARM_UNWIND_METHOD=6"));
 #endif // __arm__
 
@@ -466,11 +476,13 @@ int CoreRuntime::initialize(const char* appType, LaunchMode launchMode)
                return -1;
        }
 
-       if (launchMode == LaunchMode::loader) {
-
-               // preload libraries and manage dlls for optimizing startup time
-               preload();
+       // preload libraries and manage dlls for optimizing startup time
+       int err = pthread_create(&preloadThreadId, NULL, preloadThread, NULL);
+       if (err) {
+               _ERR("PreloadThread Creation Failed: %s", strerror(err));
+       }
 
+       if (launchMode == LaunchMode::loader) {
                // The debug pipe created in the candidate process has a "User" label.
                // As a result, smack deny occurs when app process try to access the debug pipe.
                // Also, since debugging is performed only in standalone mode,
@@ -496,7 +508,7 @@ void CoreRuntime::finalize()
        checkOnTerminate = true;
 
        // workaround : to prevent crash while process terminate on profiling mode,
-       //              kill process immediately.
+       //                              kill process immediately.
        // see https://github.com/dotnet/coreclr/issues/26687
        if (__isProfileMode) {
                _INFO("shutdown process immediately.");