Add retrying count check for waiting threads 13/286913/1
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 16 Jan 2023 23:27:29 +0000 (23:27 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 16 Jan 2023 23:27:29 +0000 (23:27 +0000)
If the retyring count is exceeded, the candidate process stops to wait for
threads ready. The maximum retrying count is 600. In the worst case,
the candidate process can be waitted until 30 seconds.

Change-Id: I4c73674c9f783499af1087c3855f56205a52a6ad
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/lib/launchpad/src/launchpad_lib.c

index af20cae..0c7dd27 100644 (file)
@@ -404,7 +404,9 @@ static unsigned int __get_thread_count(void)
 
 static void __wait_for_threads(unsigned int threads)
 {
+#define MAX_RETRYING_COUNT 600
        unsigned int thread_count;
+       unsigned int retrying_count = 0;
 
        if (threads <= 1)
                return;
@@ -412,13 +414,16 @@ static void __wait_for_threads(unsigned int threads)
        _W("Thread count = %u", threads);
        do {
                thread_count = __get_thread_count();
-               _D("Current thread count = %u", thread_count);
-               if (thread_count >= threads)
-                       break;
+               if (thread_count >= threads) {
+                       _E("Threads(%u) are ready", thread_count);
+                       return;
+               }
 
+               _D("Current thread count = %u", thread_count);
                usleep(50 * 1000);
-       } while (threads != thread_count);
-       _E("Threads(%u) are ready", thread_count);
+               retrying_count++;
+       } while (retrying_count < MAX_RETRYING_COUNT);
+       _E("Maximum retrying count exceeded");
 }
 
 static int __before_loop(int argc, char **argv)