From 8523c9ca92284ddcf90d88ec1f352f3a1aaca3b0 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 12 Nov 2012 15:29:39 +0100 Subject: [PATCH] server: use a threadpool for the mainloops --- gst/rtsp-server/rtsp-server.c | 14 +++++++++----- gst/rtsp-server/rtsp-server.h | 2 ++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/gst/rtsp-server/rtsp-server.c b/gst/rtsp-server/rtsp-server.c index 25f3666..c1d645d 100644 --- a/gst/rtsp-server/rtsp-server.c +++ b/gst/rtsp-server/rtsp-server.c @@ -58,6 +58,8 @@ G_DEFINE_TYPE (GstRTSPServer, gst_rtsp_server, G_TYPE_OBJECT); GST_DEBUG_CATEGORY_STATIC (rtsp_server_debug); #define GST_CAT_DEFAULT rtsp_server_debug +typedef struct _ClientContext ClientContext; + static guint gst_rtsp_server_signals[SIGNAL_LAST] = { 0 }; static void gst_rtsp_server_get_property (GObject * object, guint propid, @@ -66,6 +68,7 @@ static void gst_rtsp_server_set_property (GObject * object, guint propid, const GValue * value, GParamSpec * pspec); static void gst_rtsp_server_finalize (GObject * object); +static gpointer do_loop (ClientContext * ctx); static GstRTSPClient *default_create_client (GstRTSPServer * server); static gboolean default_accept_client (GstRTSPServer * server, GstRTSPClient * client, GSocket * socket, GError ** error); @@ -160,6 +163,8 @@ gst_rtsp_server_class_init (GstRTSPServerClass * klass) klass->create_client = default_create_client; klass->accept_client = default_accept_client; + klass->pool = g_thread_pool_new ((GFunc) do_loop, klass, -1, FALSE, NULL); + GST_DEBUG_CATEGORY_INIT (rtsp_server_debug, "rtspserver", 0, "GstRTSPServer"); } @@ -749,13 +754,13 @@ close_error: } } -typedef struct +struct _ClientContext { GstRTSPServer *server; GMainLoop *loop; GMainContext *context; GstRTSPClient *client; -} ClientContext; +}; static void free_client_context (ClientContext * ctx) @@ -837,10 +842,9 @@ manage_client (GstRTSPServer * server, GstRTSPClient * client) GST_RTSP_SERVER_UNLOCK (server); if (ctx->loop) { - GThread *thread; + GstRTSPServerClass *klass = GST_RTSP_SERVER_GET_CLASS (server); - thread = g_thread_new ("MainLoop Thread", (GThreadFunc) do_loop, ctx); - g_thread_unref (thread); + g_thread_pool_push (klass->pool, ctx, NULL); } } diff --git a/gst/rtsp-server/rtsp-server.h b/gst/rtsp-server/rtsp-server.h index d3500b9..c50aa87 100644 --- a/gst/rtsp-server/rtsp-server.h +++ b/gst/rtsp-server/rtsp-server.h @@ -89,6 +89,8 @@ struct _GstRTSPServer { struct _GstRTSPServerClass { GObjectClass parent_class; + GThreadPool *pool; + GstRTSPClient * (*create_client) (GstRTSPServer *server); gboolean (*accept_client) (GstRTSPServer *server, GstRTSPClient *client, GSocket *socket, GError **error); -- 2.7.4