[glib: 1/2] gtask: Separate GTask fields memory locations to avoid data races



commit fef1ce37e4c8c37d6305dd67e775db38891f33df
Author: Tomasz Miąsko <tomasz miasko gmail com>
Date:   Fri Feb 22 00:00:00 2019 +0000

    gtask: Separate GTask fields memory locations to avoid data races
    
    Ensure that fields that might be accessed in two different threads,
    through conflicting actions are stored in seprate memory locations.

 gio/gtask.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
---
diff --git a/gio/gtask.c b/gio/gtask.c
index 346d2ec5b..f6c89c974 100644
--- a/gio/gtask.c
+++ b/gio/gtask.c
@@ -563,15 +563,22 @@ struct _GTask {
   /* This can’t be in the bit field because we access it from TRACE(). */
   gboolean thread_cancelled;
 
-  gboolean check_cancellable : 1;
-  gboolean completed : 1;
-  gboolean return_on_cancel : 1;
-  gboolean synchronous : 1;
+  /* Protected by the lock when task is threaded: */
   gboolean thread_complete : 1;
-  gboolean blocking_other_task : 1;
+  gboolean return_on_cancel : 1;
+  gboolean : 0;
+
+  /* Unprotected, but written to when task runs in thread: */
+  gboolean completed : 1;
   gboolean had_error : 1;
   gboolean result_set : 1;
   gboolean ever_returned : 1;
+  gboolean : 0;
+
+  /* Read-only once task runs in thread: */
+  gboolean check_cancellable : 1;
+  gboolean synchronous : 1;
+  gboolean blocking_other_task : 1;
 
   GError *error;
   union {


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