2 * Copyright (C) 2009 Wim Taymans <wim.taymans@gmail.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
22 #include "testrtpool.h"
24 static void test_rt_pool_class_init (TestRTPoolClass * klass);
25 static void test_rt_pool_init (TestRTPool * pool);
26 static void test_rt_pool_finalize (GObject * object);
33 G_DEFINE_TYPE (TestRTPool, test_rt_pool, GST_TYPE_TASK_POOL);
36 default_prepare (GstTaskPool * pool, GError ** error)
38 /* we don't do anything here. We could construct a pool of threads here that
39 * we could reuse later but we don't */
40 g_message ("prepare Realtime pool %p", pool);
44 default_cleanup (GstTaskPool * pool)
46 g_message ("cleanup Realtime pool %p", pool);
50 default_push (GstTaskPool * pool, GstTaskPoolFunction func, gpointer data,
56 //struct sched_param param;
58 g_message ("pushing Realtime pool %p, %p", pool, func);
60 tid = g_slice_new0 (TestRTId);
62 pthread_attr_init (&attr);
64 pthread_attr_setschedpolicy (&attr, SCHED_RR);
65 param.sched_priority = 50;
66 pthread_attr_setschedparam (&attr, ¶m);
69 res = pthread_create (&tid->thread, &attr, (void *(*)(void *)) func, data);
72 g_set_error (error, G_THREAD_ERROR, G_THREAD_ERROR_AGAIN,
73 "Error creating thread: %s", g_strerror (res));
74 g_slice_free (TestRTId, tid);
82 default_join (GstTaskPool * pool, gpointer id)
84 TestRTId *tid = (TestRTId *) id;
86 g_message ("joining Realtime pool %p", pool);
88 pthread_join (tid->thread, NULL);
90 g_slice_free (TestRTId, tid);
94 test_rt_pool_class_init (TestRTPoolClass * klass)
96 GObjectClass *gobject_class;
97 GstTaskPoolClass *gsttaskpool_class;
99 gobject_class = (GObjectClass *) klass;
100 gsttaskpool_class = (GstTaskPoolClass *) klass;
102 gobject_class->finalize = GST_DEBUG_FUNCPTR (test_rt_pool_finalize);
104 gsttaskpool_class->prepare = default_prepare;
105 gsttaskpool_class->cleanup = default_cleanup;
106 gsttaskpool_class->push = default_push;
107 gsttaskpool_class->join = default_join;
111 test_rt_pool_init (TestRTPool * pool)
116 test_rt_pool_finalize (GObject * object)
118 G_OBJECT_CLASS (test_rt_pool_parent_class)->finalize (object);
122 test_rt_pool_new (void)
126 pool = g_object_new (TEST_TYPE_RT_POOL, NULL);