Document locking and its order
authorOlivier CrĂȘte <olivier.crete@collabora.com>
Mon, 18 Feb 2013 19:59:58 +0000 (14:59 -0500)
committerWim Taymans <wim.taymans@collabora.co.uk>
Mon, 11 Mar 2013 10:07:19 +0000 (11:07 +0100)
gst/rtsp-server/rtsp-address-pool.c
gst/rtsp-server/rtsp-auth.c
gst/rtsp-server/rtsp-client.c
gst/rtsp-server/rtsp-media-factory-uri.c
gst/rtsp-server/rtsp-media-factory.c
gst/rtsp-server/rtsp-media.c
gst/rtsp-server/rtsp-mount-points.c
gst/rtsp-server/rtsp-server.c
gst/rtsp-server/rtsp-session-media.c
gst/rtsp-server/rtsp-session-pool.c
gst/rtsp-server/rtsp-session.c

index b064cf7..375c25d 100644 (file)
@@ -67,7 +67,7 @@ GST_DEBUG_CATEGORY_STATIC (rtsp_address_pool_debug);
 
 struct _GstRTSPAddressPoolPrivate
 {
-  GMutex lock;
+  GMutex lock;                  /* protects everything in this struct */
   GList *addresses;
   GList *allocated;
 };
index 5a156fb..faaf0f7 100644 (file)
@@ -27,7 +27,7 @@
 struct _GstRTSPAuthPrivate
 {
   GMutex lock;
-  gchar *basic;
+  gchar *basic;                 /* protected by lock */
   GstRTSPMethod methods;
 };
 
index 4b4602c..1bb43c1 100644 (file)
 #define GST_RTSP_CLIENT_GET_PRIVATE(obj)  \
    (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_RTSP_CLIENT, GstRTSPClientPrivate))
 
+/* locking order:
+ * send_lock, lock, tunnels_lock
+ */
+
 struct _GstRTSPClientPrivate
 {
-  GMutex lock;
+  GMutex lock;                  /* protects everything else */
   GMutex send_lock;
   GstRTSPConnection *connection;
   GstRTSPWatch *watch;
@@ -38,9 +42,9 @@ struct _GstRTSPClientPrivate
   gboolean is_ipv6;
   gboolean use_client_settings;
 
-  GstRTSPClientSendFunc send_func;
-  gpointer send_data;
-  GDestroyNotify send_notify;
+  GstRTSPClientSendFunc send_func;      /* protected by send_lock */
+  gpointer send_data;           /* protected by send_lock */
+  GDestroyNotify send_notify;   /* protected by send_lock */
 
   GstRTSPSessionPool *session_pool;
   GstRTSPMountPoints *mount_points;
@@ -54,7 +58,7 @@ struct _GstRTSPClientPrivate
 };
 
 static GMutex tunnels_lock;
-static GHashTable *tunnels;
+static GHashTable *tunnels;     /* protected by tunnels_lock */
 
 #define DEFAULT_SESSION_POOL            NULL
 #define DEFAULT_MOUNT_POINTS            NULL
index c83d87d..e2e80d9 100644 (file)
@@ -27,7 +27,7 @@
 struct _GstRTSPMediaFactoryURIPrivate
 {
   GMutex lock;
-  gchar *uri;
+  gchar *uri;                   /* protected by lock */
   gboolean use_gstpay;
 
   GstCaps *raw_vcaps;
index cd4b1a7..ced81ec 100644 (file)
@@ -28,7 +28,7 @@
 
 struct _GstRTSPMediaFactoryPrivate
 {
-  GMutex lock;
+  GMutex lock;                  /* protects everything but medias */
   gchar *launch;
   gboolean shared;
   gboolean eos_shutdown;
@@ -38,7 +38,7 @@ struct _GstRTSPMediaFactoryPrivate
   GstRTSPAddressPool *pool;
 
   GMutex medias_lock;
-  GHashTable *medias;
+  GHashTable *medias;           /* protected by medias_lock */
 };
 
 #define DEFAULT_LAUNCH          NULL
@@ -799,9 +799,9 @@ no_launch:
   }
 parse_error:
   {
-    GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
     g_critical ("could not parse launch syntax (%s): %s", priv->launch,
         (error ? error->message : "unknown reason"));
+    GST_RTSP_MEDIA_FACTORY_UNLOCK (factory);
     if (error)
       g_error_free (error);
     return NULL;
index 10610ff..9826a1d 100644 (file)
@@ -33,6 +33,7 @@ struct _GstRTSPMediaPrivate
   GMutex lock;
   GCond cond;
 
+  /* protected by lock */
   gboolean shared;
   gboolean reusable;
   GstRTSPLowerTrans protocols;
@@ -43,17 +44,17 @@ struct _GstRTSPMediaPrivate
   GstRTSPAddressPool *pool;
 
   GstElement *element;
-  GRecMutex state_lock;
-  GPtrArray *streams;
-  GList *dynamic;
-  GstRTSPMediaStatus status;
+  GRecMutex state_lock;         /* locking order: state lock, lock */
+  GPtrArray *streams;           /* protected by lock */
+  GList *dynamic;               /* protected by lock */
+  GstRTSPMediaStatus status;    /* protected by lock */
   gint prepare_count;
   gint n_active;
   gboolean adding;
 
   /* the pipeline for the media */
   GstElement *pipeline;
-  GstElement *fakesink;
+  GstElement *fakesink;         /* protected by lock */
   GSource *source;
   guint id;
 
@@ -66,7 +67,7 @@ struct _GstRTSPMediaPrivate
   GstElement *rtpbin;
 
   /* the range of media */
-  GstRTSPTimeRange range;
+  GstRTSPTimeRange range;       /* protected by lock */
   GstClockTime range_start;
   GstClockTime range_stop;
 };
index c18cb63..3d3b61c 100644 (file)
@@ -25,7 +25,7 @@
 struct _GstRTSPMountPointsPrivate
 {
   GMutex lock;
-  GHashTable *mounts;
+  GHashTable *mounts;           /* protected by lock */
 };
 
 G_DEFINE_TYPE (GstRTSPMountPoints, gst_rtsp_mount_points, G_TYPE_OBJECT);
index f66b23a..f41b390 100644 (file)
@@ -32,7 +32,7 @@
 
 struct _GstRTSPServerPrivate
 {
-  GMutex lock;
+  GMutex lock;                  /* protects everything in this struct */
 
   /* server information */
   gchar *address;
index fb4d71c..d708163 100644 (file)
 struct _GstRTSPSessionMediaPrivate
 {
   GMutex lock;
-  GstRTSPUrl *url;
-  GstRTSPMedia *media;
-  GstRTSPState state;
-  guint counter;
+  GstRTSPUrl *url;              /* unmutable */
+  GstRTSPMedia *media;          /* unmutable */
+  GstRTSPState state;           /* protected by lock */
+  guint counter;                /* protected by lock */
 
-  GPtrArray *transports;
+  GPtrArray *transports;        /* protected by lock */
 };
 
 enum
index 2fe209f..c4709c5 100644 (file)
@@ -24,9 +24,8 @@
 
 struct _GstRTSPSessionPoolPrivate
 {
+  GMutex lock;                  /* protects everything in this struct */
   guint max_sessions;
-
-  GMutex lock;
   GHashTable *sessions;
 };
 
index f50a476..87d03ff 100644 (file)
 
 struct _GstRTSPSessionPrivate
 {
-  GMutex lock;
+  GMutex lock;                  /* protects everything but sessionid and create_time */
   gchar *sessionid;
 
   guint timeout;
-  GTimeVal create_time;
+  GTimeVal create_time;         /* immutable */
   GTimeVal last_access;
   gint expire_count;