TaskPool: remove _set_func()
[platform/upstream/gstreamer.git] / tests / examples / streams / testrtpool.c
1 /* GStreamer
2  * Copyright (C) 2009 Wim Taymans <wim.taymans@gmail.com>
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include <pthread.h>
21
22 #include "testrtpool.h"
23
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);
27
28 typedef struct
29 {
30   pthread_t thread;
31 } TestRTId;
32
33 G_DEFINE_TYPE (TestRTPool, test_rt_pool, GST_TYPE_TASK_POOL);
34
35 static void
36 default_prepare (GstTaskPool * pool, GError ** error)
37 {
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);
41 }
42
43 static void
44 default_cleanup (GstTaskPool * pool)
45 {
46   g_message ("cleanup Realtime pool %p", pool);
47 }
48
49 static gpointer
50 default_push (GstTaskPool * pool, GstTaskPoolFunction func, gpointer data,
51     GError ** error)
52 {
53   TestRTId *tid;
54   gint res;
55   pthread_attr_t attr;
56   //struct sched_param param;
57
58   g_message ("pushing Realtime pool %p, %p", pool, func);
59
60   tid = g_slice_new0 (TestRTId);
61
62   pthread_attr_init (&attr);
63   /* 
64      pthread_attr_setschedpolicy (&attr, SCHED_RR);
65      param.sched_priority = 50;
66      pthread_attr_setschedparam (&attr, &param);
67    */
68
69   res = pthread_create (&tid->thread, &attr, (void *(*)(void *)) func, data);
70
71   if (res < 0) {
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);
75     tid = NULL;
76   }
77
78   return tid;
79 }
80
81 static void
82 default_join (GstTaskPool * pool, gpointer id)
83 {
84   TestRTId *tid = (TestRTId *) id;
85
86   g_message ("joining Realtime pool %p", pool);
87
88   pthread_join (tid->thread, NULL);
89
90   g_slice_free (TestRTId, tid);
91 }
92
93 static void
94 test_rt_pool_class_init (TestRTPoolClass * klass)
95 {
96   GObjectClass *gobject_class;
97   GstTaskPoolClass *gsttaskpool_class;
98
99   gobject_class = (GObjectClass *) klass;
100   gsttaskpool_class = (GstTaskPoolClass *) klass;
101
102   gobject_class->finalize = GST_DEBUG_FUNCPTR (test_rt_pool_finalize);
103
104   gsttaskpool_class->prepare = default_prepare;
105   gsttaskpool_class->cleanup = default_cleanup;
106   gsttaskpool_class->push = default_push;
107   gsttaskpool_class->join = default_join;
108 }
109
110 static void
111 test_rt_pool_init (TestRTPool * pool)
112 {
113 }
114
115 static void
116 test_rt_pool_finalize (GObject * object)
117 {
118   G_OBJECT_CLASS (test_rt_pool_parent_class)->finalize (object);
119 }
120
121 GstTaskPool *
122 test_rt_pool_new (void)
123 {
124   GstTaskPool *pool;
125
126   pool = g_object_new (TEST_TYPE_RT_POOL, NULL);
127
128   return pool;
129 }