mot-agent: fixed crash issue
authorsaerome.kim <saerome.kim@samsung.com>
Mon, 28 May 2018 08:03:18 +0000 (17:03 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Tue, 3 Jul 2018 01:43:26 +0000 (10:43 +0900)
About 10 hours aging test, we found 1 crash issue.
In the same case that thread does not die even wait time elasped,
so change margin time from 5 seconds to 10 seconds.

Signed-off-by: saerome.kim <saerome.kim@samsung.com>
src/mot-agent/ma-subowner.c

index 2ef0167..e6a579b 100644 (file)
@@ -47,7 +47,8 @@
 
 #define DISCOVERY_TIMEOUT  6 /**< 6 sec */
 #define CALLBACK_TIMEOUT_5S 5 * 1000 /**< 5sec = 5 * 1000 * 1ms */
-#define TIME_UNIT 100 /**< Sleep time unit */
+#define CALLBACK_MARGIN 10 * 1000 /**< 10sec */
+#define TIME_UNIT 10 /**< Sleep time unit */
 
 /* '_' for separaing from the same constant variable in srmresourcestrings.c  */
 static const char* SVR_DB_FILE_NAME = "oic_svr_db_ma.dat";
@@ -152,7 +153,7 @@ static void* _exec_and_wait(void* args)
                TIMES += 1;
 
        while (!g_client->g_doneCB && proc->data <= TIMES) {
-               /* Increase 100 msec */
+               /* Increase wait time per unit time (= 10 msec) */
                time_to_wait.tv_sec = time(NULL);
                time_to_wait.tv_nsec = TIME_UNIT * 1000000;
 
@@ -189,7 +190,7 @@ static int _init_proc(process_t *proc, void *(*routine) (void *))
 
        return MA_ERROR_NONE;
 }
-#endif
+#endif /* THREAD_COND_WAIT_USED */
 
 static FILE* _fopen_prvn_mng(const char* path, const char* mode)
 {
@@ -224,7 +225,7 @@ static int _wait_cb_ret(int msec)
 
        strcpy(proc.name, "A\0");
        proc.data = 0;
-       proc.waits = msec + CALLBACK_TIMEOUT_5S;
+       proc.waits = msec + CALLBACK_MARGIN;
 
        if (0 != _init_proc(&proc, _exec_and_wait)) {
                MA_LOGE("Fail to init proc [%s]", proc.name);
@@ -232,11 +233,8 @@ static int _wait_cb_ret(int msec)
        }
        pthread_join(proc.thread, &result);
 #else
-       for (int i = 0; !g_client->g_doneCB && (msec + CALLBACK_TIMEOUT_5S) >= i; i += 10) {
-               /*
-                 * Basically, nanosleep is more thread-safe function,
-                 * But, in our case, nanosleep cause crash frequently
-                 */
+       for (int i = 0; !g_client->g_doneCB && (msec + CALLBACK_MARGIN) >= i; i += TIME_UNIT) {
+
                result = nanosleep(&tim, &tim2);
                if (0 > result)
                        MA_LOGE("nanosleep failed=%d", errno);