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