eliminate race condition
authorJunkyeong Kim <jk0430.kim@samsung.com>
Thu, 3 Dec 2015 12:50:52 +0000 (21:50 +0900)
committerBoram Park <boram1288.park@samsung.com>
Fri, 4 Dec 2015 02:33:07 +0000 (11:33 +0900)
Change-Id: I9a76a4d631ad4a479bd59cdb487c99a79c3446d1
Signed-off-by: Junkyeong Kim <jk0430.kim@samsung.com>
src/tdm_display.c
src/tdm_private.h

index 9e40cd62576b5c08dfc055a1f5c7a1f4d4f5744b..52ae2e3f297e653338f62b7e76ded5d0e4a7a8e7 100644 (file)
@@ -563,14 +563,28 @@ static void
 _tdm_output_cb_vblank(tdm_output *output, unsigned int sequence,
                       unsigned int tv_sec, unsigned int tv_usec, void *user_data)
 {
-    tdm_private_output *private_output = output;
+    tdm_private_output *private_output;
+    tdm_private_display *private_display;
+    tdm_private_display *private_display_backend;
     tdm_private_vblank_handler *vblank_handler = user_data;
+    TDM_RETURN_IF_FAIL(vblank_handler);
 
+    private_output = vblank_handler->private_output;
     TDM_RETURN_IF_FAIL(private_output);
-    TDM_RETURN_IF_FAIL(vblank_handler);
+
+    private_display = private_output->private_display;
+    LIST_FOR_EACH_ENTRY(private_output, &private_display->output_list, link)
+    {
+        if (private_output->output == output)
+            private_display_backend = private_output->private_display;
+    }
+
+    pthread_mutex_unlock(&private_display_backend->lock);
 
     if (vblank_handler->func)
-        vblank_handler->func(private_output, sequence, tv_sec, tv_usec, vblank_handler->user_data);
+        vblank_handler->func(vblank_handler->private_output, sequence, tv_sec, tv_usec, vblank_handler->user_data);
+
+    pthread_mutex_lock(&private_display_backend->lock);
 
     LIST_DEL(&vblank_handler->link);
     free(vblank_handler);
@@ -580,14 +594,28 @@ static void
 _tdm_output_cb_commit(tdm_output *output, unsigned int sequence,
                       unsigned int tv_sec, unsigned int tv_usec, void *user_data)
 {
-    tdm_private_output *private_output = output;
+    tdm_private_output *private_output;
+    tdm_private_display *private_display;
+    tdm_private_display *private_display_backend;
     tdm_private_commit_handler *commit_handler = user_data;
+    TDM_RETURN_IF_FAIL(commit_handler);
 
+    private_output = commit_handler->private_output;
     TDM_RETURN_IF_FAIL(private_output);
-    TDM_RETURN_IF_FAIL(commit_handler);
+
+    private_display = private_output->private_display;
+    LIST_FOR_EACH_ENTRY(private_output, &private_display->output_list, link)
+    {
+        if (private_output->output == output)
+            private_display_backend = private_output->private_display;
+    }
+
+    pthread_mutex_unlock(&private_display_backend->lock);
 
     if (commit_handler->func)
-        commit_handler->func(private_output, sequence, tv_sec, tv_usec, commit_handler->user_data);
+        commit_handler->func(commit_handler->private_output, sequence, tv_sec, tv_usec, commit_handler->user_data);
+
+    pthread_mutex_lock(&private_display_backend->lock);
 
     LIST_DEL(&commit_handler->link);
     free(commit_handler);
@@ -619,6 +647,7 @@ tdm_output_wait_vblank(tdm_output *output, int interval, int sync, tdm_output_vb
     }
 
     LIST_ADD(&vblank_handler->link, &private_output->vblank_handler_list);
+    vblank_handler->private_output = private_output;
     vblank_handler->func = func;
     vblank_handler->user_data = user_data;
 
@@ -666,6 +695,7 @@ tdm_output_commit(tdm_output *output, int sync, tdm_output_commit_handler func,
     }
 
     LIST_ADD(&commit_handler->link, &private_output->commit_handler_list);
+    commit_handler->private_output = private_output;
     commit_handler->func = func;
     commit_handler->user_data = user_data;
 
index 804db34360e7f6e778735a6ce309cb4ef29edb90..3f0b7338e89e9a5f4acbb9c73fb41b4c1e41b593 100644 (file)
@@ -241,6 +241,7 @@ struct _tdm_private_vblank_handler
 {
     struct list_head link;
 
+    tdm_private_output *private_output;
     tdm_output_vblank_handler func;
     void *user_data;
 };
@@ -249,6 +250,7 @@ struct _tdm_private_commit_handler
 {
     struct list_head link;
 
+    tdm_private_output *private_output;
     tdm_output_commit_handler func;
     void *user_data;
 };