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;
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);
((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;
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,
&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);
+
}