[gnome-builder] ide-subprocess: count outstanding operations beforehand



commit 5e25df70257d55bbb992b9f89398697b22f7ddee
Author: Cosimo Cecchi <cosimo endlessm com>
Date:   Wed Dec 28 19:15:21 2016 -0800

    ide-subprocess: count outstanding operations beforehand
    
    Instead of adding up when triggering operations, increase the count
    beforehand. That way, even if an operation happens to complete before
    returning from the thread, we'll always correctly wait for all of them
    to be completed before returning the task.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=779976

 libide/subprocess/ide-breakout-subprocess.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
---
diff --git a/libide/subprocess/ide-breakout-subprocess.c b/libide/subprocess/ide-breakout-subprocess.c
index beb7c3e..0426f51 100644
--- a/libide/subprocess/ide-breakout-subprocess.c
+++ b/libide/subprocess/ide-breakout-subprocess.c
@@ -779,6 +779,14 @@ ide_breakout_subprocess_communicate_internal (IdeBreakoutSubprocess *subprocess,
       g_source_attach (state->cancellable_source, g_main_context_get_thread_default ());
     }
 
+  /* Increment the outstanding ops count, to protect from reentrancy */
+  if (subprocess->stdin_pipe)
+    state->outstanding_ops++;
+  if (subprocess->stdout_pipe)
+    state->outstanding_ops++;
+  if (subprocess->stderr_pipe)
+    state->outstanding_ops++;
+
   if (subprocess->stdin_pipe)
     {
       g_assert (stdin_buf != NULL);
@@ -787,7 +795,6 @@ ide_breakout_subprocess_communicate_internal (IdeBreakoutSubprocess *subprocess,
                                     G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | 
G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
                                     G_PRIORITY_DEFAULT, state->cancellable,
                                     ide_subprocess_communicate_made_progress, g_object_ref (task));
-      state->outstanding_ops++;
     }
 
   if (subprocess->stdout_pipe)
@@ -797,7 +804,6 @@ ide_breakout_subprocess_communicate_internal (IdeBreakoutSubprocess *subprocess,
                                     G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE,
                                     G_PRIORITY_DEFAULT, state->cancellable,
                                     ide_subprocess_communicate_made_progress, g_object_ref (task));
-      state->outstanding_ops++;
     }
 
   if (subprocess->stderr_pipe)
@@ -807,7 +813,6 @@ ide_breakout_subprocess_communicate_internal (IdeBreakoutSubprocess *subprocess,
                                     G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE,
                                     G_PRIORITY_DEFAULT, state->cancellable,
                                     ide_subprocess_communicate_made_progress, g_object_ref (task));
-      state->outstanding_ops++;
     }
 
   ide_subprocess_wait_async (IDE_SUBPROCESS (subprocess), state->cancellable,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]