[glib/glib-2-30] schedule_write_in_worker_thread: require caller to lock; rename accordingly



commit 210c0c0cd581cdf0af5a691c7e065001bb7be00b
Author: Simon McVittie <simon mcvittie collabora co uk>
Date:   Fri Oct 21 14:46:47 2011 +0100

    schedule_write_in_worker_thread: require caller to lock; rename accordingly
    
    When we use this function to schedule a flush, it'll be called
    with the lock held. Releasing and immediately re-taking the lock would
    be pointless.
    
    Bug: https://bugzilla.gnome.org/show_bug.cgi?id=662395
    Signed-off-by: Simon McVittie <simon mcvittie collabora co uk>
    Reviewed-by: Cosimo Alfarano <cosimo alfarano collabora co uk>

 gio/gdbusprivate.c |   20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)
---
diff --git a/gio/gdbusprivate.c b/gio/gdbusprivate.c
index 0b8506f..28cfeac 100644
--- a/gio/gdbusprivate.c
+++ b/gio/gdbusprivate.c
@@ -1528,16 +1528,14 @@ continue_writing_in_idle_cb (gpointer user_data)
  *
  * Can be called from any thread
  *
- * write_lock is not held on entry
+ * write_lock is held on entry
  * output_pending may be anything
  */
 static void
-schedule_write_in_worker_thread (GDBusWorker        *worker,
-                                 MessageToWriteData *write_data,
-                                 CloseData          *close_data)
+schedule_writing_unlocked (GDBusWorker        *worker,
+                           MessageToWriteData *write_data,
+                           CloseData          *close_data)
 {
-  g_mutex_lock (worker->write_lock);
-
   if (write_data != NULL)
     g_queue_push_tail (worker->write_queue, write_data);
 
@@ -1557,8 +1555,6 @@ schedule_write_in_worker_thread (GDBusWorker        *worker,
       g_source_attach (idle_source, worker->shared_thread_data->context);
       g_source_unref (idle_source);
     }
-
-  g_mutex_unlock (worker->write_lock);
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
@@ -1586,7 +1582,9 @@ _g_dbus_worker_send_message (GDBusWorker    *worker,
   data->blob = blob; /* steal! */
   data->blob_size = blob_len;
 
-  schedule_write_in_worker_thread (worker, data, NULL);
+  g_mutex_lock (worker->write_lock);
+  schedule_writing_unlocked (worker, data, NULL);
+  g_mutex_unlock (worker->write_lock);
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
@@ -1669,7 +1667,9 @@ _g_dbus_worker_close (GDBusWorker         *worker,
    * It'll be set before the actual close happens.
    */
   g_cancellable_cancel (worker->cancellable);
-  schedule_write_in_worker_thread (worker, NULL, close_data);
+  g_mutex_lock (worker->write_lock);
+  schedule_writing_unlocked (worker, NULL, close_data);
+  g_mutex_unlock (worker->write_lock);
 }
 
 /* This can be called from any thread - frees worker. Note that



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