2009-04-23 17:42:47 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2009 Wim Taymans <wim.taymans@gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2009-04-24 10:35:08 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
|
2009-04-23 17:42:47 +00:00
|
|
|
#include "testrtpool.h"
|
|
|
|
|
|
|
|
static void test_rt_pool_finalize (GObject * object);
|
|
|
|
|
2009-04-24 10:35:08 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
pthread_t thread;
|
|
|
|
} TestRTId;
|
|
|
|
|
2009-04-23 17:42:47 +00:00
|
|
|
G_DEFINE_TYPE (TestRTPool, test_rt_pool, GST_TYPE_TASK_POOL);
|
|
|
|
|
|
|
|
static void
|
2009-04-24 10:35:08 +00:00
|
|
|
default_prepare (GstTaskPool * pool, GError ** error)
|
2009-04-23 17:42:47 +00:00
|
|
|
{
|
2009-04-24 10:35:08 +00:00
|
|
|
/* we don't do anything here. We could construct a pool of threads here that
|
|
|
|
* we could reuse later but we don't */
|
2009-04-23 17:42:47 +00:00
|
|
|
g_message ("prepare Realtime pool %p", pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
default_cleanup (GstTaskPool * pool)
|
|
|
|
{
|
|
|
|
g_message ("cleanup Realtime pool %p", pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gpointer
|
2009-04-24 10:35:08 +00:00
|
|
|
default_push (GstTaskPool * pool, GstTaskPoolFunction func, gpointer data,
|
|
|
|
GError ** error)
|
2009-04-23 17:42:47 +00:00
|
|
|
{
|
2009-04-24 10:35:08 +00:00
|
|
|
TestRTId *tid;
|
|
|
|
gint res;
|
|
|
|
pthread_attr_t attr;
|
2009-04-24 11:55:13 +00:00
|
|
|
struct sched_param param;
|
2009-04-24 10:35:08 +00:00
|
|
|
|
|
|
|
g_message ("pushing Realtime pool %p, %p", pool, func);
|
2009-04-23 17:42:47 +00:00
|
|
|
|
2009-04-24 10:35:08 +00:00
|
|
|
tid = g_slice_new0 (TestRTId);
|
2009-04-23 17:42:47 +00:00
|
|
|
|
2009-04-24 11:55:13 +00:00
|
|
|
g_message ("set policy");
|
2009-04-24 10:35:08 +00:00
|
|
|
pthread_attr_init (&attr);
|
2009-04-24 11:55:13 +00:00
|
|
|
if ((res = pthread_attr_setschedpolicy (&attr, SCHED_RR)) != 0)
|
|
|
|
g_warning ("setschedpolicy: failure: %p", g_strerror (res));
|
2009-04-24 10:35:08 +00:00
|
|
|
|
2009-04-24 11:55:13 +00:00
|
|
|
g_message ("set prio");
|
|
|
|
param.sched_priority = 50;
|
|
|
|
if ((res = pthread_attr_setschedparam (&attr, ¶m)) != 0)
|
|
|
|
g_warning ("setschedparam: failure: %p", g_strerror (res));
|
|
|
|
|
|
|
|
g_message ("set inherit");
|
|
|
|
if ((res = pthread_attr_setinheritsched (&attr, PTHREAD_EXPLICIT_SCHED)) != 0)
|
|
|
|
g_warning ("setinheritsched: failure: %p", g_strerror (res));
|
|
|
|
|
|
|
|
g_message ("create thread");
|
2009-04-24 10:35:08 +00:00
|
|
|
res = pthread_create (&tid->thread, &attr, (void *(*)(void *)) func, data);
|
|
|
|
|
2009-04-24 11:55:13 +00:00
|
|
|
if (res != 0) {
|
2009-04-24 10:35:08 +00:00
|
|
|
g_set_error (error, G_THREAD_ERROR, G_THREAD_ERROR_AGAIN,
|
|
|
|
"Error creating thread: %s", g_strerror (res));
|
|
|
|
g_slice_free (TestRTId, tid);
|
|
|
|
tid = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return tid;
|
2009-04-23 17:42:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
default_join (GstTaskPool * pool, gpointer id)
|
|
|
|
{
|
2009-04-24 10:35:08 +00:00
|
|
|
TestRTId *tid = (TestRTId *) id;
|
|
|
|
|
2009-04-23 17:42:47 +00:00
|
|
|
g_message ("joining Realtime pool %p", pool);
|
2009-04-24 10:35:08 +00:00
|
|
|
|
|
|
|
pthread_join (tid->thread, NULL);
|
|
|
|
|
|
|
|
g_slice_free (TestRTId, tid);
|
2009-04-23 17:42:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_rt_pool_class_init (TestRTPoolClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstTaskPoolClass *gsttaskpool_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gsttaskpool_class = (GstTaskPoolClass *) klass;
|
|
|
|
|
|
|
|
gobject_class->finalize = GST_DEBUG_FUNCPTR (test_rt_pool_finalize);
|
|
|
|
|
|
|
|
gsttaskpool_class->prepare = default_prepare;
|
|
|
|
gsttaskpool_class->cleanup = default_cleanup;
|
|
|
|
gsttaskpool_class->push = default_push;
|
|
|
|
gsttaskpool_class->join = default_join;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_rt_pool_init (TestRTPool * pool)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_rt_pool_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
G_OBJECT_CLASS (test_rt_pool_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
GstTaskPool *
|
|
|
|
test_rt_pool_new (void)
|
|
|
|
{
|
|
|
|
GstTaskPool *pool;
|
|
|
|
|
|
|
|
pool = g_object_new (TEST_TYPE_RT_POOL, NULL);
|
|
|
|
|
|
|
|
return pool;
|
|
|
|
}
|