1 /* GSequencer - Advanced GTK Sequencer
2  * Copyright (C) 2005-2020 Joël Krähemann
3  *
4  * This file is part of GSequencer.
5  *
6  * GSequencer is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * GSequencer is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with GSequencer.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <ags/thread/ags_concurrency_provider.h>
21 
22 #include <math.h>
23 
24 void ags_concurrency_provider_class_init(AgsConcurrencyProviderInterface *ginterface);
25 
26 /**
27  * SECTION:ags_concurrency_provider
28  * @short_description: concurrency provider interface
29  * @title: AgsConcurrencyProvider
30  * @section_id: AgsConcurrencyProvider
31  * @include: ags/thread/ags_concurrency_provider.h
32  *
33  * The #AgsConcurrencyProvider gives you unique access to threads.
34  */
35 
36 GType
ags_concurrency_provider_get_type()37 ags_concurrency_provider_get_type()
38 {
39   static volatile gsize g_define_type_id__volatile = 0;
40 
41   if(g_once_init_enter (&g_define_type_id__volatile)){
42     GType ags_type_concurrency_provider = 0;
43 
44     ags_type_concurrency_provider = g_type_register_static_simple(G_TYPE_INTERFACE,
45 								  "AgsConcurrencyProvider",
46 								  sizeof(AgsConcurrencyProviderInterface),
47 								  (GClassInitFunc) ags_concurrency_provider_class_init,
48 								  0, NULL, 0);
49 
50     g_once_init_leave(&g_define_type_id__volatile, ags_type_concurrency_provider);
51   }
52 
53   return g_define_type_id__volatile;
54 }
55 
56 void
ags_concurrency_provider_class_init(AgsConcurrencyProviderInterface * ginterface)57 ags_concurrency_provider_class_init(AgsConcurrencyProviderInterface *ginterface)
58 {
59   /* empty */
60 }
61 
62 /**
63  * ags_concurrency_provider_get_main_loop:
64  * @concurrency_provider: the #AgsConcurrencyProvider
65  *
66  * Get main loop of application context.
67  *
68  * Returns: (transfer full): the #AgsThread implementing #AgsMainLoop
69  *
70  * Since: 3.0.0
71  */
72 AgsThread*
ags_concurrency_provider_get_main_loop(AgsConcurrencyProvider * concurrency_provider)73 ags_concurrency_provider_get_main_loop(AgsConcurrencyProvider *concurrency_provider)
74 {
75   AgsConcurrencyProviderInterface *concurrency_provider_interface;
76 
77   g_return_val_if_fail(AGS_IS_CONCURRENCY_PROVIDER(concurrency_provider), NULL);
78   concurrency_provider_interface = AGS_CONCURRENCY_PROVIDER_GET_INTERFACE(concurrency_provider);
79   g_return_val_if_fail(concurrency_provider_interface->get_main_loop, NULL);
80 
81   return(concurrency_provider_interface->get_main_loop(concurrency_provider));
82 }
83 
84 /**
85  * ags_concurrency_provider_set_main_loop:
86  * @concurrency_provider: the #AgsConcurrencyProvider
87  * @main_loop: the #AgsThread implementing #AgsMainLoop
88  *
89  * Set main loop of application context.
90  *
91  * Since: 3.0.0
92  */
93 void
ags_concurrency_provider_set_main_loop(AgsConcurrencyProvider * concurrency_provider,AgsThread * main_loop)94 ags_concurrency_provider_set_main_loop(AgsConcurrencyProvider *concurrency_provider,
95 				       AgsThread *main_loop)
96 {
97   AgsConcurrencyProviderInterface *concurrency_provider_interface;
98 
99   g_return_if_fail(AGS_IS_CONCURRENCY_PROVIDER(concurrency_provider));
100   concurrency_provider_interface = AGS_CONCURRENCY_PROVIDER_GET_INTERFACE(concurrency_provider);
101   g_return_if_fail(concurrency_provider_interface->set_main_loop);
102 
103   concurrency_provider_interface->set_main_loop(concurrency_provider,
104 						main_loop);
105 }
106 
107 /**
108  * ags_concurrency_provider_get_task_launcher:
109  * @concurrency_provider: the #AgsConcurrencyProvider
110  *
111  * Get task launcher of application context.
112  *
113  * Returns: (transfer full): the #AgsTaskLauncher
114  *
115  * Since: 3.0.0
116  */
117 AgsTaskLauncher*
ags_concurrency_provider_get_task_launcher(AgsConcurrencyProvider * concurrency_provider)118 ags_concurrency_provider_get_task_launcher(AgsConcurrencyProvider *concurrency_provider)
119 {
120   AgsConcurrencyProviderInterface *concurrency_provider_interface;
121 
122   g_return_val_if_fail(AGS_IS_CONCURRENCY_PROVIDER(concurrency_provider), NULL);
123   concurrency_provider_interface = AGS_CONCURRENCY_PROVIDER_GET_INTERFACE(concurrency_provider);
124   g_return_val_if_fail(concurrency_provider_interface->get_task_launcher, NULL);
125 
126   return(concurrency_provider_interface->get_task_launcher(concurrency_provider));
127 }
128 
129 /**
130  * ags_concurrency_provider_set_task_launcher:
131  * @concurrency_provider: the #AgsConcurrencyProvider
132  * @task_launcher: the #AgsTaskLauncher
133  *
134  * Set task launcher of application context.
135  *
136  * Since: 3.0.0
137  */
138 void
ags_concurrency_provider_set_task_launcher(AgsConcurrencyProvider * concurrency_provider,AgsTaskLauncher * task_launcher)139 ags_concurrency_provider_set_task_launcher(AgsConcurrencyProvider *concurrency_provider,
140 					   AgsTaskLauncher *task_launcher)
141 {
142   AgsConcurrencyProviderInterface *concurrency_provider_interface;
143 
144   g_return_if_fail(AGS_IS_CONCURRENCY_PROVIDER(concurrency_provider));
145   concurrency_provider_interface = AGS_CONCURRENCY_PROVIDER_GET_INTERFACE(concurrency_provider);
146   g_return_if_fail(concurrency_provider_interface->set_task_launcher);
147 
148   concurrency_provider_interface->set_task_launcher(concurrency_provider,
149 						    task_launcher);
150 }
151 
152 /**
153  * ags_concurrency_provider_get_thread_pool:
154  * @concurrency_provider: the #AgsConcurrencyProvider
155  *
156  * Get thread pool of application context.
157  *
158  * Returns: (transfer full): the #AgsThreadPool
159  *
160  * Since: 3.0.0
161  */
162 AgsThreadPool*
ags_concurrency_provider_get_thread_pool(AgsConcurrencyProvider * concurrency_provider)163 ags_concurrency_provider_get_thread_pool(AgsConcurrencyProvider *concurrency_provider)
164 {
165   AgsConcurrencyProviderInterface *concurrency_provider_interface;
166 
167   g_return_val_if_fail(AGS_IS_CONCURRENCY_PROVIDER(concurrency_provider), NULL);
168   concurrency_provider_interface = AGS_CONCURRENCY_PROVIDER_GET_INTERFACE(concurrency_provider);
169   g_return_val_if_fail(concurrency_provider_interface->get_thread_pool, NULL);
170 
171   return(concurrency_provider_interface->get_thread_pool(concurrency_provider));
172 }
173 
174 /**
175  * ags_concurrency_provider_set_thread_pool:
176  * @concurrency_provider: the #AgsConcurrencyProvider
177  * @thread_pool: the #AgsThreadPool
178  *
179  * Set thread pool of application context.
180  *
181  * Since: 3.0.0
182  */
183 void
ags_concurrency_provider_set_thread_pool(AgsConcurrencyProvider * concurrency_provider,AgsThreadPool * thread_pool)184 ags_concurrency_provider_set_thread_pool(AgsConcurrencyProvider *concurrency_provider,
185 					 AgsThreadPool *thread_pool)
186 {
187   AgsConcurrencyProviderInterface *concurrency_provider_interface;
188 
189   g_return_if_fail(AGS_IS_CONCURRENCY_PROVIDER(concurrency_provider));
190   concurrency_provider_interface = AGS_CONCURRENCY_PROVIDER_GET_INTERFACE(concurrency_provider);
191   g_return_if_fail(concurrency_provider_interface->set_thread_pool);
192 
193   concurrency_provider_interface->set_thread_pool(concurrency_provider,
194 						  thread_pool);
195 }
196 
197 /**
198  * ags_concurrency_provider_get_worker:
199  * @concurrency_provider: the #AgsConcurrencyProvider
200  *
201  * Get workers of application context.
202  *
203  * Returns: (element-type Ags.WorkerThread) (transfer full): the #GList-struct containing workers
204  *
205  * Since: 3.0.0
206  */
207 GList*
ags_concurrency_provider_get_worker(AgsConcurrencyProvider * concurrency_provider)208 ags_concurrency_provider_get_worker(AgsConcurrencyProvider *concurrency_provider)
209 {
210   AgsConcurrencyProviderInterface *concurrency_provider_interface;
211 
212   g_return_val_if_fail(AGS_IS_CONCURRENCY_PROVIDER(concurrency_provider), NULL);
213   concurrency_provider_interface = AGS_CONCURRENCY_PROVIDER_GET_INTERFACE(concurrency_provider);
214   g_return_val_if_fail(concurrency_provider_interface->get_worker, NULL);
215 
216   return(concurrency_provider_interface->get_worker(concurrency_provider));
217 }
218 
219 /**
220  * ags_concurrency_provider_set_worker:
221  * @concurrency_provider: the #AgsConcurrencyProvider
222  * @worker: (element-type Ags.WorkerThread): the #GList-struct containing workers
223  *
224  * Set workers of application context.
225  *
226  * Since: 3.0.0
227  */
228 void
ags_concurrency_provider_set_worker(AgsConcurrencyProvider * concurrency_provider,GList * worker)229 ags_concurrency_provider_set_worker(AgsConcurrencyProvider *concurrency_provider,
230 				    GList *worker)
231 {
232   AgsConcurrencyProviderInterface *concurrency_provider_interface;
233 
234   g_return_if_fail(AGS_IS_CONCURRENCY_PROVIDER(concurrency_provider));
235   concurrency_provider_interface = AGS_CONCURRENCY_PROVIDER_GET_INTERFACE(concurrency_provider);
236   g_return_if_fail(concurrency_provider_interface->set_worker);
237 
238   concurrency_provider_interface->set_worker(concurrency_provider,
239 					     worker);
240 }
241