[farsight2/master] Use regular GMutex instead of static mutex and add some debugging functions

Olivier Crête olivier.crete at collabora.co.uk
Fri Dec 19 17:36:02 PST 2008


---
 gst/fsrtpconference/fs-rtp-session.c |    5 +++--
 gst/fsrtpconference/fs-rtp-session.h |   27 +++++++++++++++++++++++----
 2 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/gst/fsrtpconference/fs-rtp-session.c b/gst/fsrtpconference/fs-rtp-session.c
index cd522c1..7d68d06 100644
--- a/gst/fsrtpconference/fs-rtp-session.c
+++ b/gst/fsrtpconference/fs-rtp-session.c
@@ -369,7 +369,7 @@ fs_rtp_session_init (FsRtpSession *self)
   self->priv->transmitters = g_hash_table_new_full (g_str_hash, g_str_equal,
     g_free, g_object_unref);
 
-  g_static_mutex_init (&self->mutex);
+  self->mutex = g_mutex_new ();
 
   self->priv->media_type = FS_MEDIA_TYPE_LAST + 1;
 
@@ -655,7 +655,8 @@ fs_rtp_session_finalize (GObject *object)
 {
   FsRtpSession *self = FS_RTP_SESSION (object);
 
-  g_static_mutex_free (&self->mutex);
+  g_mutex_free (self->mutex);
+  self->mutex = NULL;
 
   if (self->priv->codec_preferences)
     fs_codec_list_destroy (self->priv->codec_preferences);
diff --git a/gst/fsrtpconference/fs-rtp-session.h b/gst/fsrtpconference/fs-rtp-session.h
index 6e48254..17adf0f 100644
--- a/gst/fsrtpconference/fs-rtp-session.h
+++ b/gst/fsrtpconference/fs-rtp-session.h
@@ -70,16 +70,35 @@ struct _FsRtpSession
   /* This ID can be accessed by the stream/substreams for this session */
   guint id;
 
-  GStaticMutex mutex; /* Should only be accessed using the macros */
+  GMutex *mutex; /* Should only be accessed using the macros */
+
+#ifdef DEBUG_MUTEXES
+  guint count;
+#endif
 
   FsRtpSessionPrivate *priv;
 };
 
+#ifdef DEBUG_MUTEXES
+
 #define FS_RTP_SESSION_LOCK(session) \
-  g_static_mutex_lock (&FS_RTP_SESSION (session)->mutex)
+  do { \
+    g_mutex_lock (FS_RTP_SESSION (session)->mutex);   \
+    g_assert (FS_RTP_SESSION (session)->count == 0);  \
+    FS_RTP_SESSION (session)->count++;                \
+  } while (0);
 #define FS_RTP_SESSION_UNLOCK(session) \
-  g_static_mutex_unlock (&FS_RTP_SESSION (session)->mutex)
-
+  do { \
+    g_assert (FS_RTP_SESSION (session)->count == 1);  \
+    FS_RTP_SESSION (session)->count--;                \
+    g_mutex_unlock (FS_RTP_SESSION (session)->mutex); \
+  } while (0);
+#else
+#define FS_RTP_SESSION_LOCK(session) \
+  g_mutex_lock (FS_RTP_SESSION_CAST (session)->mutex)
+#define FS_RTP_SESSION_UNLOCK(session) \
+  g_mutex_unlock (FS_RTP_SESSION_CAST (session)->mutex)
+#endif
 
 GType fs_rtp_session_get_type (void);
 
-- 
1.5.6.5




More information about the farsight-commits mailing list