thread-pool: store thread type in thread

This commit is contained in:
Wim Taymans 2013-07-10 20:48:18 +02:00
parent 4e9c4d8bb7
commit 8cec0f8a46
2 changed files with 23 additions and 19 deletions

View file

@ -70,19 +70,21 @@ gst_rtsp_thread_init (GstRTSPThreadImpl * impl)
/**
* gst_rtsp_thread_new:
* @type: the thread type
*
* Create a new thread object that can run a mainloop.
*
* Returns: a #GstRTSPThread.
*/
GstRTSPThread *
gst_rtsp_thread_new (void)
gst_rtsp_thread_new (GstRTSPThreadType type)
{
GstRTSPThreadImpl *impl;
impl = g_slice_new0 (GstRTSPThreadImpl);
gst_rtsp_thread_init (impl);
impl->thread.type = type;
impl->thread.context = g_main_context_new ();
impl->thread.loop = g_main_loop_new (impl->thread.context, TRUE);
@ -355,14 +357,15 @@ gst_rtsp_thread_pool_get_max_threads (GstRTSPThreadPool * pool)
}
static GstRTSPThread *
make_thread (GstRTSPThreadPool * pool, GstRTSPClientState * state)
make_thread (GstRTSPThreadPool * pool, GstRTSPThreadType type,
GstRTSPClientState * state)
{
GstRTSPThreadPoolClass *klass;
GstRTSPThread *thread;
klass = GST_RTSP_THREAD_POOL_GET_CLASS (pool);
thread = gst_rtsp_thread_new ();
thread = gst_rtsp_thread_new (type);
gst_mini_object_set_qdata (GST_MINI_OBJECT (thread), thread_pool,
g_object_ref (pool), g_object_unref);
@ -401,7 +404,7 @@ default_get_thread (GstRTSPThreadPool * pool,
} else {
/* make more threads */
GST_DEBUG_OBJECT (pool, "make new client thread");
thread = make_thread (pool, state);
thread = make_thread (pool, type, state);
if (!g_thread_pool_push (klass->pool, thread, &error))
goto thread_error;
@ -411,7 +414,7 @@ default_get_thread (GstRTSPThreadPool * pool,
break;
case GST_RTSP_THREAD_TYPE_MEDIA:
GST_DEBUG_OBJECT (pool, "make new media thread");
thread = make_thread (pool, state);
thread = make_thread (pool, type, state);
if (!g_thread_pool_push (klass->pool, thread, &error))
goto thread_error;

View file

@ -47,6 +47,19 @@ GType gst_rtsp_thread_get_type (void);
#define GST_RTSP_THREAD_CAST(obj) ((GstRTSPThread*)(obj))
#define GST_RTSP_THREAD(obj) (GST_RTSP_THREAD_CAST(obj))
/**
* GstRTSPThreadType:
* @GST_RTSP_THREAD_TYPE_CLIENT: a thread to handle the client communication
* @GST_RTSP_THREAD_TYPE_MEDIA: a thread to handle media
*
* Different thread types
*/
typedef enum
{
GST_RTSP_THREAD_TYPE_CLIENT,
GST_RTSP_THREAD_TYPE_MEDIA
} GstRTSPThreadType;
/**
* GstRTSPThread:
*
@ -55,11 +68,12 @@ GType gst_rtsp_thread_get_type (void);
struct _GstRTSPThread {
GstMiniObject mini_object;
GstRTSPThreadType type;
GMainContext *context;
GMainLoop *loop;
};
GstRTSPThread * gst_rtsp_thread_new (void);
GstRTSPThread * gst_rtsp_thread_new (GstRTSPThreadType type);
void gst_rtsp_thread_reuse (GstRTSPThread * thread);
void gst_rtsp_thread_stop (GstRTSPThread * thread);
@ -99,19 +113,6 @@ gst_rtsp_thread_unref (GstRTSPThread * thread)
gst_mini_object_unref (GST_MINI_OBJECT_CAST (thread));
}
/**
* GstRTSPThreadType:
* @GST_RTSP_THREAD_TYPE_CLIENT: a thread to handle the client communication
* @GST_RTSP_THREAD_TYPE_MEDIA: a thread to handle media
*
* Different thread types
*/
typedef enum
{
GST_RTSP_THREAD_TYPE_CLIENT,
GST_RTSP_THREAD_TYPE_MEDIA
} GstRTSPThreadType;
/**
* GstRTSPThreadPool:
*