[glib/glib-2-28] GDBusWorker: as a precaution, access 'stopped' boolean atomically



commit e128c045eba9508982da133c3fda9e0d7b0588ba
Author: Simon McVittie <simon mcvittie collabora co uk>
Date:   Thu Sep 8 17:21:43 2011 +0100

    GDBusWorker: as a precaution, access 'stopped' boolean atomically
    
    This member is written in _g_dbus_worker_stop from arbitrary threads, and
    read by the worker thread, so it should be accessed atomically.
    
    Bug: https://bugzilla.gnome.org/show_bug.cgi?id=651268
    Bug-NB: NB#271520
    Signed-off-by: Simon McVittie <simon mcvittie collabora co uk>
    Signed-off-by: David Zeuthen <davidz redhat com>

 gio/gdbusprivate.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
---
diff --git a/gio/gdbusprivate.c b/gio/gdbusprivate.c
index ada2778..0cfffbb 100644
--- a/gio/gdbusprivate.c
+++ b/gio/gdbusprivate.c
@@ -392,7 +392,8 @@ struct GDBusWorker
 {
   volatile gint                       ref_count;
 
-  gboolean                            stopped;
+  /* really a boolean, but GLib 2.28 lacks atomic boolean ops */
+  volatile gint                       stopped;
 
   /* TODO: frozen (e.g. G_DBUS_CONNECTION_FLAGS_DELAY_MESSAGE_PROCESSING) currently
    * only affects messages received from the other peer (since GDBusServer is the
@@ -526,7 +527,7 @@ _g_dbus_worker_emit_disconnected (GDBusWorker  *worker,
                                   gboolean      remote_peer_vanished,
                                   GError       *error)
 {
-  if (!worker->stopped)
+  if (!g_atomic_int_get (&worker->stopped))
     worker->disconnected_callback (worker, remote_peer_vanished, error, worker->user_data);
 }
 
@@ -534,7 +535,7 @@ static void
 _g_dbus_worker_emit_message_received (GDBusWorker  *worker,
                                       GDBusMessage *message)
 {
-  if (!worker->stopped)
+  if (!g_atomic_int_get (&worker->stopped))
     worker->message_received_callback (worker, message, worker->user_data);
 }
 
@@ -543,7 +544,7 @@ _g_dbus_worker_emit_message_about_to_be_sent (GDBusWorker  *worker,
                                               GDBusMessage *message)
 {
   GDBusMessage *ret;
-  if (!worker->stopped)
+  if (!g_atomic_int_get (&worker->stopped))
     ret = worker->message_about_to_be_sent_callback (worker, message, worker->user_data);
   else
     ret = message;
@@ -625,7 +626,7 @@ _g_dbus_worker_do_read_cb (GInputStream  *input_stream,
   g_mutex_lock (worker->read_lock);
 
   /* If already stopped, don't even process the reply */
-  if (worker->stopped)
+  if (g_atomic_int_get (&worker->stopped))
     goto out;
 
   error = NULL;
@@ -1684,7 +1685,7 @@ _g_dbus_worker_close (GDBusWorker         *worker,
 void
 _g_dbus_worker_stop (GDBusWorker *worker)
 {
-  worker->stopped = TRUE;
+  g_atomic_int_set (&worker->stopped, TRUE);
 
   /* cancel any pending operations and schedule a close of the underlying I/O
    * stream in the worker thread



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