[FIX] replay events 35/27735/1
authorVitaliy Cherepanov <v.cherepanov@samsung.com>
Thu, 18 Sep 2014 10:17:35 +0000 (14:17 +0400)
committerVitaliy Cherepanov <v.cherepanov@samsung.com>
Thu, 18 Sep 2014 10:17:35 +0000 (14:17 +0400)
replay events feature does not work

Change-Id: Ide5bd4322d49228f669de01bd9d87ecac3545638
Signed-off-by: Vitaliy Cherepanov <v.cherepanov@samsung.com>
daemon/da_protocol.c
daemon/daemon.c
daemon/threads.c

index 86ffa3f..a28f4ac 100644 (file)
@@ -658,6 +658,7 @@ enum ErrorCode stop_all_no_lock(void)
                msg = gen_stop_msg();
                terminate_all();
                stop_profiling();
+               stop_replay();
 
                if (msg == NULL) {
                        LOGE("cannot generate stop message\n");
index d903788..2f2bfc4 100644 (file)
@@ -521,31 +521,31 @@ static int target_event_pid_handler(struct target *target)
 
        target_set_type(target);
 
-       if (0) {        // main application (index == 0)
-               app_info = app_info_get_first(&app);
-               if (app_info == NULL) {
-                       LOGE("No app info found\n");
-                       return -1;
-               }
+       /* posible need some process check right there before start_replay >> */
+       app_info = app_info_get_first(&app);
+       if (app_info == NULL) {
+               LOGE("No app info found\n");
+               return -1;
+       }
 
-               while (app_info != NULL) {
-                       if (is_same_app_process(app_info->exe_path,
-                                               target_get_pid(target)))
-                               break;
-                       app_info = app_info_get_next(&app);
-               }
+       while (app_info != NULL) {
+               if (is_same_app_process(app_info->exe_path,
+                                       target_get_pid(target)))
+                       break;
+               app_info = app_info_get_next(&app);
+       }
 
-               if (app_info == NULL) {
-                       LOGE("pid %d not found in app list\n",
-                            target_get_pid(target));
-                       return -1;
-               }
+       if (app_info == NULL) {
+               LOGE("pid %d not found in app list\n",
+                    target_get_pid(target));
+               return -1;
+       }
 
-               if (start_replay() != 0) {
-                       LOGE("Cannot start replay thread\n");
-                       return -1;
-               }
+       if (start_replay() != 0) {
+               LOGE("Cannot start replay thread\n");
+               return -1;
        }
+       /* posible need some process check right there before start_replay << */
 
        target->initial_log = 1;
 
@@ -560,9 +560,6 @@ static int target_event_stop_handler(struct target *target)
        LOGI("target[%p] close, pid(%d) : (remaining %d target)\n",
             target, target_get_pid(target), target_cnt_get() - 1);
 
-       if (0)          // main application (index == 0)
-               stop_replay();
-
        ecore_main_fd_handler_del(target->handler);
 
        target_dtor(target);
index 3cbd85a..d75b263 100644 (file)
@@ -322,6 +322,16 @@ static useconds_t time_diff_us(struct timeval *tv1, struct timeval *tv2)
                ((int)tv1->tv_usec - (int)tv2->tv_usec);
 }
 
+static pthread_mutex_t replay_thread_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+static void exit_replay_thread()
+{
+       pthread_mutex_lock(&replay_thread_mutex);
+       manager.replay_thread = -1;
+       reset_replay_event_seq(&prof_session.replay_event_seq);
+       pthread_mutex_unlock(&replay_thread_mutex);
+}
+
 static void *replay_thread(void *arg)
 {
        struct replay_event_seq_t *event_seq = (struct replay_event_seq_t *)arg;
@@ -359,13 +369,22 @@ static void *replay_thread(void *arg)
 
        LOGI("replay events thread finished\n");
 
+       exit_replay_thread();
+
        return arg;
 }
 
 int start_replay()
 {
-       if (manager.replay_thread != -1) // already started
-               return 1;
+       int res = 0;
+
+       pthread_mutex_lock(&replay_thread_mutex);
+
+       if (manager.replay_thread != -1) {
+               LOGI("replay already started\n");
+               res = 1;
+               goto exit;
+       }
 
        if (pthread_create(&(manager.replay_thread),
                           NULL,
@@ -373,22 +392,33 @@ int start_replay()
                           &prof_session.replay_event_seq) < 0)
        {
                LOGE("Failed to create replay thread\n");
-               return 1;
+               res = 1;
+               goto exit;
        }
 
-       return 0;
+exit:
+       pthread_mutex_unlock(&replay_thread_mutex);
+       return res;
 }
 
+
 void stop_replay()
 {
+       pthread_mutex_lock(&replay_thread_mutex);
+
        if (manager.replay_thread == -1) {
                LOGI("replay thread not running\n");
-               return;
+               goto exit;
        }
        LOGI("stopping replay thread\n");
        pthread_cancel(manager.replay_thread);
        pthread_join(manager.replay_thread, NULL);
        manager.replay_thread = -1;
-       reset_replay_event_seq(&prof_session.replay_event_seq);
        LOGI("replay thread joined\n");
+
+       reset_replay_event_seq(&prof_session.replay_event_seq);
+
+exit:
+       pthread_mutex_unlock(&replay_thread_mutex);
+
 }