telepathy-logger: log-walker: Treat the internal state as a critical section

Nicolas Dufresne nicolasd at kemper.freedesktop.org
Tue Aug 28 13:01:06 PDT 2012


Module: telepathy-logger
Branch: master
Commit: e2283df2fe5e894067edc5dcbe5207c6ad365d06
URL:    http://cgit.freedesktop.org/telepathy/telepathy-logger/commit/?id=e2283df2fe5e894067edc5dcbe5207c6ad365d06

Author: Debarshi Ray <debarshir at freedesktop.org>
Date:   Thu Jul  5 12:18:02 2012 +0200

log-walker: Treat the internal state as a critical section

Since the TplLogWalker API is asynchronous, we do not want multiple
overlapping calls to stamp on each others' toes.

Fixes: https://bugs.freedesktop.org/41772

---

 telepathy-logger/log-walker.c |   34 ++++++++++++++++++++++++++++++++--
 1 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/telepathy-logger/log-walker.c b/telepathy-logger/log-walker.c
index b400a07..9abc2e0 100644
--- a/telepathy-logger/log-walker.c
+++ b/telepathy-logger/log-walker.c
@@ -45,6 +45,7 @@ struct _TplLogWalkerPriv
 {
   GList *caches;
   GList *iters;
+  GMutex mutex;
   gboolean is_begin;
   gboolean is_end;
 };
@@ -113,6 +114,8 @@ tpl_log_walker_get_events (TplLogWalker *walker,
   events = NULL;
   i = 0;
 
+  g_mutex_lock (&priv->mutex);
+
   if (priv->is_end == TRUE)
     goto out;
 
@@ -173,6 +176,8 @@ tpl_log_walker_get_events (TplLogWalker *walker,
     priv->is_begin = FALSE;
 
  out:
+  g_mutex_unlock (&priv->mutex);
+
   return events;
 }
 
@@ -222,6 +227,11 @@ tpl_log_walker_dispose (GObject *object)
 static void
 tpl_log_walker_finalize (GObject *object)
 {
+  TplLogWalkerPriv *priv;
+
+  priv = TPL_LOG_WALKER (object)->priv;
+  g_mutex_clear (&priv->mutex);
+
   G_OBJECT_CLASS (tpl_log_walker_parent_class)->finalize (object);
 }
 
@@ -235,6 +245,8 @@ tpl_log_walker_init (TplLogWalker *walker)
       TplLogWalkerPriv);
   priv = walker->priv;
 
+  g_mutex_init (&priv->mutex);
+
   priv->is_begin = TRUE;
   priv->is_end = FALSE;
 }
@@ -360,7 +372,16 @@ tpl_log_walker_get_events_finish (TplLogWalker *walker,
 gboolean
 tpl_log_walker_is_begin (TplLogWalker *walker)
 {
-  return walker->priv->is_begin;
+  TplLogWalkerPriv *priv;
+  gboolean retval;
+
+  priv = walker->priv;
+
+  g_mutex_lock (&priv->mutex);
+  retval = priv->is_begin;
+  g_mutex_unlock (&priv->mutex);
+
+  return retval;
 }
 
 
@@ -376,5 +397,14 @@ tpl_log_walker_is_begin (TplLogWalker *walker)
 gboolean
 tpl_log_walker_is_end (TplLogWalker *walker)
 {
-  return walker->priv->is_end;
+  TplLogWalkerPriv *priv;
+  gboolean retval;
+
+  priv = walker->priv;
+
+  g_mutex_lock (&priv->mutex);
+  retval = priv->is_end;
+  g_mutex_unlock (&priv->mutex);
+
+  return retval;
 }



More information about the telepathy-commits mailing list