1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gdk.Threads;
26 
27 private import gtkc.gdk;
28 public  import gtkc.gdktypes;
29 
30 
31 /** */
32 
33 /**
34  * A wrapper for the common usage of gdk_threads_add_idle_full()
35  * assigning the default priority, #G_PRIORITY_DEFAULT_IDLE.
36  *
37  * See gdk_threads_add_idle_full().
38  *
39  * Params:
40  *     funct = function to call
41  *     data = data to pass to @function
42  *
43  * Returns: the ID (greater than 0) of the event source.
44  *
45  * Since: 2.12
46  */
47 public uint threadsAddIdle(GSourceFunc funct, void* data)
48 {
49 	return gdk_threads_add_idle(funct, data);
50 }
51 
52 /**
53  * Adds a function to be called whenever there are no higher priority
54  * events pending.  If the function returns %FALSE it is automatically
55  * removed from the list of event sources and will not be called again.
56  *
57  * This variant of g_idle_add_full() calls @function with the GDK lock
58  * held. It can be thought of a MT-safe version for GTK+ widgets for the
59  * following use case, where you have to worry about idle_callback()
60  * running in thread A and accessing @self after it has been finalized
61  * in thread B:
62  *
63  * |[<!-- language="C" -->
64  * static gboolean
65  * idle_callback (gpointer data)
66  * {
67  * // gdk_threads_enter(); would be needed for g_idle_add()
68  *
69  * SomeWidget *self = data;
70  * // do stuff with self
71  *
72  * self->idle_id = 0;
73  *
74  * // gdk_threads_leave(); would be needed for g_idle_add()
75  * return FALSE;
76  * }
77  *
78  * static void
79  * some_widget_do_stuff_later (SomeWidget *self)
80  * {
81  * self->idle_id = gdk_threads_add_idle (idle_callback, self)
82  * // using g_idle_add() here would require thread protection in the callback
83  * }
84  *
85  * static void
86  * some_widget_finalize (GObject *object)
87  * {
88  * SomeWidget *self = SOME_WIDGET (object);
89  * if (self->idle_id)
90  * g_source_remove (self->idle_id);
91  * G_OBJECT_CLASS (parent_class)->finalize (object);
92  * }
93  * ]|
94  *
95  * Params:
96  *     priority = the priority of the idle source. Typically this will be in the
97  *         range between #G_PRIORITY_DEFAULT_IDLE and #G_PRIORITY_HIGH_IDLE
98  *     funct = function to call
99  *     data = data to pass to @function
100  *     notify = function to call when the idle is removed, or %NULL
101  *
102  * Returns: the ID (greater than 0) of the event source.
103  *
104  * Since: 2.12
105  */
106 public uint threadsAddIdleFull(int priority, GSourceFunc funct, void* data, GDestroyNotify notify)
107 {
108 	return gdk_threads_add_idle_full(priority, funct, data, notify);
109 }
110 
111 /**
112  * A wrapper for the common usage of gdk_threads_add_timeout_full()
113  * assigning the default priority, #G_PRIORITY_DEFAULT.
114  *
115  * See gdk_threads_add_timeout_full().
116  *
117  * Params:
118  *     interval = the time between calls to the function, in milliseconds
119  *         (1/1000ths of a second)
120  *     funct = function to call
121  *     data = data to pass to @function
122  *
123  * Returns: the ID (greater than 0) of the event source.
124  *
125  * Since: 2.12
126  */
127 public uint threadsAddTimeout(uint interval, GSourceFunc funct, void* data)
128 {
129 	return gdk_threads_add_timeout(interval, funct, data);
130 }
131 
132 /**
133  * Sets a function to be called at regular intervals holding the GDK lock,
134  * with the given priority.  The function is called repeatedly until it
135  * returns %FALSE, at which point the timeout is automatically destroyed
136  * and the function will not be called again.  The @notify function is
137  * called when the timeout is destroyed.  The first call to the
138  * function will be at the end of the first @interval.
139  *
140  * Note that timeout functions may be delayed, due to the processing of other
141  * event sources. Thus they should not be relied on for precise timing.
142  * After each call to the timeout function, the time of the next
143  * timeout is recalculated based on the current time and the given interval
144  * (it does not try to “catch up” time lost in delays).
145  *
146  * This variant of g_timeout_add_full() can be thought of a MT-safe version
147  * for GTK+ widgets for the following use case:
148  *
149  * |[<!-- language="C" -->
150  * static gboolean timeout_callback (gpointer data)
151  * {
152  * SomeWidget *self = data;
153  *
154  * // do stuff with self
155  *
156  * self->timeout_id = 0;
157  *
158  * return G_SOURCE_REMOVE;
159  * }
160  *
161  * static void some_widget_do_stuff_later (SomeWidget *self)
162  * {
163  * self->timeout_id = g_timeout_add (timeout_callback, self)
164  * }
165  *
166  * static void some_widget_finalize (GObject *object)
167  * {
168  * SomeWidget *self = SOME_WIDGET (object);
169  *
170  * if (self->timeout_id)
171  * g_source_remove (self->timeout_id);
172  *
173  * G_OBJECT_CLASS (parent_class)->finalize (object);
174  * }
175  * ]|
176  *
177  * Params:
178  *     priority = the priority of the timeout source. Typically this will be in the
179  *         range between #G_PRIORITY_DEFAULT_IDLE and #G_PRIORITY_HIGH_IDLE.
180  *     interval = the time between calls to the function, in milliseconds
181  *         (1/1000ths of a second)
182  *     funct = function to call
183  *     data = data to pass to @function
184  *     notify = function to call when the timeout is removed, or %NULL
185  *
186  * Returns: the ID (greater than 0) of the event source.
187  *
188  * Since: 2.12
189  */
190 public uint threadsAddTimeoutFull(int priority, uint interval, GSourceFunc funct, void* data, GDestroyNotify notify)
191 {
192 	return gdk_threads_add_timeout_full(priority, interval, funct, data, notify);
193 }
194 
195 /**
196  * A wrapper for the common usage of gdk_threads_add_timeout_seconds_full()
197  * assigning the default priority, #G_PRIORITY_DEFAULT.
198  *
199  * For details, see gdk_threads_add_timeout_full().
200  *
201  * Params:
202  *     interval = the time between calls to the function, in seconds
203  *     funct = function to call
204  *     data = data to pass to @function
205  *
206  * Returns: the ID (greater than 0) of the event source.
207  *
208  * Since: 2.14
209  */
210 public uint threadsAddTimeoutSeconds(uint interval, GSourceFunc funct, void* data)
211 {
212 	return gdk_threads_add_timeout_seconds(interval, funct, data);
213 }
214 
215 /**
216  * A variant of gdk_threads_add_timeout_full() with second-granularity.
217  * See g_timeout_add_seconds_full() for a discussion of why it is
218  * a good idea to use this function if you don’t need finer granularity.
219  *
220  * Params:
221  *     priority = the priority of the timeout source. Typically this will be in the
222  *         range between #G_PRIORITY_DEFAULT_IDLE and #G_PRIORITY_HIGH_IDLE.
223  *     interval = the time between calls to the function, in seconds
224  *     funct = function to call
225  *     data = data to pass to @function
226  *     notify = function to call when the timeout is removed, or %NULL
227  *
228  * Returns: the ID (greater than 0) of the event source.
229  *
230  * Since: 2.14
231  */
232 public uint threadsAddTimeoutSecondsFull(int priority, uint interval, GSourceFunc funct, void* data, GDestroyNotify notify)
233 {
234 	return gdk_threads_add_timeout_seconds_full(priority, interval, funct, data, notify);
235 }
236 
237 /**
238  * This function marks the beginning of a critical section in which
239  * GDK and GTK+ functions can be called safely and without causing race
240  * conditions. Only one thread at a time can be in such a critial
241  * section.
242  *
243  * Deprecated: All GDK and GTK+ calls should be made from the main
244  * thread
245  */
246 public void threadsEnter()
247 {
248 	gdk_threads_enter();
249 }
250 
251 /**
252  * Initializes GDK so that it can be used from multiple threads
253  * in conjunction with gdk_threads_enter() and gdk_threads_leave().
254  *
255  * This call must be made before any use of the main loop from
256  * GTK+; to be safe, call it before gtk_init().
257  *
258  * Deprecated: All GDK and GTK+ calls should be made from the main
259  * thread
260  */
261 public void threadsInit()
262 {
263 	gdk_threads_init();
264 }
265 
266 /**
267  * Leaves a critical region begun with gdk_threads_enter().
268  *
269  * Deprecated: All GDK and GTK+ calls should be made from the main
270  * thread
271  */
272 public void threadsLeave()
273 {
274 	gdk_threads_leave();
275 }
276 
277 /**
278  * Allows the application to replace the standard method that
279  * GDK uses to protect its data structures. Normally, GDK
280  * creates a single #GMutex that is locked by gdk_threads_enter(),
281  * and released by gdk_threads_leave(); using this function an
282  * application provides, instead, a function @enter_fn that is
283  * called by gdk_threads_enter() and a function @leave_fn that is
284  * called by gdk_threads_leave().
285  *
286  * The functions must provide at least same locking functionality
287  * as the default implementation, but can also do extra application
288  * specific processing.
289  *
290  * As an example, consider an application that has its own recursive
291  * lock that when held, holds the GTK+ lock as well. When GTK+ unlocks
292  * the GTK+ lock when entering a recursive main loop, the application
293  * must temporarily release its lock as well.
294  *
295  * Most threaded GTK+ apps won’t need to use this method.
296  *
297  * This method must be called before gdk_threads_init(), and cannot
298  * be called multiple times.
299  *
300  * Deprecated: All GDK and GTK+ calls should be made from the main
301  * thread
302  *
303  * Params:
304  *     enterFn = function called to guard GDK
305  *     leaveFn = function called to release the guard
306  *
307  * Since: 2.4
308  */
309 public void threadsSetLockFunctions(GCallback enterFn, GCallback leaveFn)
310 {
311 	gdk_threads_set_lock_functions(enterFn, leaveFn);
312 }