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_finalize (GObject * object);
31 G_DEFINE_TYPE (TestRTPool, test_rt_pool, GST_TYPE_TASK_POOL);
34 default_prepare (GstTaskPool * pool, GError ** error)
36 /* we don't do anything here. We could construct a pool of threads here that
37 * we could reuse later but we don't */
38 g_message ("prepare Realtime pool %p", pool);
42 default_cleanup (GstTaskPool * pool)
44 g_message ("cleanup Realtime pool %p", pool);
48 default_push (GstTaskPool * pool, GstTaskPoolFunction func, gpointer data,
54 struct sched_param param;
56 g_message ("pushing Realtime pool %p, %p", pool, func);
58 tid = g_slice_new0 (TestRTId);
60 g_message ("set policy");
61 pthread_attr_init (&attr);
62 if ((res = pthread_attr_setschedpolicy (&attr, SCHED_RR)) != 0)
63 g_warning ("setschedpolicy: failure: %p", g_strerror (res));
65 g_message ("set prio");
66 param.sched_priority = 50;
67 if ((res = pthread_attr_setschedparam (&attr, ¶m)) != 0)
68 g_warning ("setschedparam: failure: %p", g_strerror (res));
70 g_message ("set inherit");
71 if ((res = pthread_attr_setinheritsched (&attr, PTHREAD_EXPLICIT_SCHED)) != 0)
72 g_warning ("setinheritsched: failure: %p", g_strerror (res));
74 g_message ("create thread");
75 res = pthread_create (&tid->thread, &attr, (void *(*)(void *)) func, data);
78 g_set_error (error, G_THREAD_ERROR, G_THREAD_ERROR_AGAIN,
79 "Error creating thread: %s", g_strerror (res));
80 g_slice_free (TestRTId, tid);
88 default_join (GstTaskPool * pool, gpointer id)
90 TestRTId *tid = (TestRTId *) id;
92 g_message ("joining Realtime pool %p", pool);
94 pthread_join (tid->thread, NULL);
96 g_slice_free (TestRTId, tid);
100 test_rt_pool_class_init (TestRTPoolClass * klass)
102 GObjectClass *gobject_class;
103 GstTaskPoolClass *gsttaskpool_class;
105 gobject_class = (GObjectClass *) klass;
106 gsttaskpool_class = (GstTaskPoolClass *) klass;
108 gobject_class->finalize = GST_DEBUG_FUNCPTR (test_rt_pool_finalize);
110 gsttaskpool_class->prepare = default_prepare;
111 gsttaskpool_class->cleanup = default_cleanup;
112 gsttaskpool_class->push = default_push;
113 gsttaskpool_class->join = default_join;
117 test_rt_pool_init (TestRTPool * pool)
122 test_rt_pool_finalize (GObject * object)
124 G_OBJECT_CLASS (test_rt_pool_parent_class)->finalize (object);
128 test_rt_pool_new (void)
132 pool = g_object_new (TEST_TYPE_RT_POOL, NULL);