[virglrenderer-devel] [PATCH] renderer: prevent losing condvar signals for fence_cond

ramin.azarmehr at gmail.com ramin.azarmehr at gmail.com
Wed Jun 13 20:34:45 UTC 2018


From: Ramin Azarmehr <ramin.azarmehr at gmail.com>

Signaling a CondVar without the Mutex locked could possibly cause the waiting-fence to miss the wakeup.
More info: https://stackoverflow.com/questions/4544234/calling-pthread-cond-signal-without-locking-mutex
---
 src/vrend_renderer.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c
index c7f41a4..439a555 100644
--- a/src/vrend_renderer.c
+++ b/src/vrend_renderer.c
@@ -4013,9 +4013,9 @@ static void vrend_free_sync_thread(void)
 
    pipe_mutex_lock(vrend_state.fence_mutex);
    vrend_state.stop_sync_thread = true;
+   pipe_condvar_signal(vrend_state.fence_cond);
    pipe_mutex_unlock(vrend_state.fence_mutex);
 
-   pipe_condvar_signal(vrend_state.fence_cond);
    pipe_thread_wait(vrend_state.sync_thread);
    vrend_state.sync_thread = 0;
 
@@ -6249,8 +6249,8 @@ int vrend_renderer_create_fence(int client_fence_id, uint32_t ctx_id)
    if (vrend_state.sync_thread) {
       pipe_mutex_lock(vrend_state.fence_mutex);
       list_addtail(&fence->fences, &vrend_state.fence_wait_list);
-      pipe_mutex_unlock(vrend_state.fence_mutex);
       pipe_condvar_signal(vrend_state.fence_cond);
+      pipe_mutex_unlock(vrend_state.fence_mutex);
    } else
       list_addtail(&fence->fences, &vrend_state.fence_list);
    return 0;
-- 
2.17.1



More information about the virglrenderer-devel mailing list