alternative to assert
[gtkD.git] / gtkD / src / gthread / StaticPrivate.d
blob9d2f0cee2b50f70d7174863fea14bd0d58f922d5
1 /*
2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD 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
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile =
26 * outPack = gthread
27 * outFile = StaticPrivate
28 * strct = GStaticPrivate
29 * realStrct=
30 * ctorStrct=
31 * clss = StaticPrivate
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - g_static_private_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * imports:
44 * - glib.Dataset
45 * structWrap:
46 * - GDataset* -> Dataset
47 * module aliases:
48 * local aliases:
51 module gthread.StaticPrivate;
53 version(noAssert)
55 version(Tango)
57 import tango.io.Stdout; // use the tango loging?
61 private import gtkc.gthreadtypes;
63 private import gtkc.gthread;
66 private import glib.Dataset;
71 /**
72 * Description
73 * Threads act almost like processes, but unlike processes all threads of
74 * one process share the same memory. This is good, as it provides easy
75 * communication between the involved threads via this shared memory, and
76 * it is bad, because strange things (so called "Heisenbugs") might
77 * happen if the program is not carefully designed. In particular, due to
78 * the concurrent nature of threads, no assumptions on the order of
79 * execution of code running in different threads can be made, unless
80 * order is explicitly forced by the programmer through synchronization
81 * primitives.
82 * The aim of the thread related functions in GLib is to provide a
83 * portable means for writing multi-threaded software. There are
84 * primitives for mutexes to protect the access to portions of memory
85 * (GMutex, GStaticMutex, G_LOCK_DEFINE, GStaticRecMutex and
86 * GStaticRWLock). There are primitives for condition variables to allow
87 * synchronization of threads (GCond). There are primitives
88 * for thread-private data - data that every thread has a private instance of
89 * (GPrivate, GStaticPrivate). Last but definitely not least there are
90 * primitives to portably create and manage threads (GThread).
91 * You must call g_thread_init() before executing any other GLib
92 * functions in a threaded GLib program. After that, GLib is completely
93 * thread safe (all global data is automatically locked), but individual
94 * data structure instances are not automatically locked for performance
95 * reasons. So, for example you must coordinate accesses to the same
96 * GHashTable from multiple threads. The two notable exceptions from
97 * this rule are GMainLoop and GAsyncQueue,
98 * which are threadsafe and needs no further
99 * application-level locking to be accessed from multiple threads.
101 public class StaticPrivate
104 /** the main Gtk struct */
105 protected GStaticPrivate* gStaticPrivate;
108 public GStaticPrivate* getStaticPrivateStruct()
110 return gStaticPrivate;
114 /** the main Gtk struct as a void* */
115 protected void* getStruct()
117 return cast(void*)gStaticPrivate;
121 * Sets our main struct and passes it to the parent class
123 public this (GStaticPrivate* gStaticPrivate)
125 version(noAssert)
127 if ( gStaticPrivate is null )
129 int zero = 0;
130 version(Tango)
132 Stdout("struct gStaticPrivate is null on constructor").newline;
134 else
136 printf("struct gStaticPrivate is null on constructor");
138 zero = zero / zero;
141 else
143 assert(gStaticPrivate !is null, "struct gStaticPrivate is null on constructor");
145 this.gStaticPrivate = gStaticPrivate;
223 * Initializes private_key. Alternatively you can initialize it with
224 * G_STATIC_PRIVATE_INIT.
225 * private_key:
226 * a GStaticPrivate to be initialized.
228 public void init()
230 // void g_static_private_init (GStaticPrivate *private_key);
231 g_static_private_init(gStaticPrivate);
235 * Works like g_private_get() only for a GStaticPrivate.
236 * This function works even if g_thread_init() has not yet been called.
237 * private_key:
238 * a GStaticPrivate.
239 * Returns:
240 * the corresponding pointer.
242 public void* get()
244 // gpointer g_static_private_get (GStaticPrivate *private_key);
245 return g_static_private_get(gStaticPrivate);
249 * Sets the pointer keyed to private_key for the current thread and the
250 * function notify to be called with that pointer (NULL or non-NULL),
251 * whenever the pointer is set again or whenever the current thread ends.
252 * This function works even if g_thread_init() has not yet been
253 * called. If g_thread_init() is called later, the data keyed to
254 * private_key will be inherited only by the main thread, i.e. the one that
255 * called g_thread_init().
256 * Note
257 * notify is used quite differently from destructor in
258 * g_private_new().
259 * private_key:
260 * a GStaticPrivate.
261 * data:
262 * the new pointer.
263 * notify:
264 * a function to be called with the pointer whenever the
265 * current thread ends or sets this pointer again.
267 public void set(void* data, GDestroyNotify notify)
269 // void g_static_private_set (GStaticPrivate *private_key, gpointer data, GDestroyNotify notify);
270 g_static_private_set(gStaticPrivate, data, notify);
274 * Releases all resources allocated to private_key.
275 * You don't have to call this functions for a GStaticPrivate with an
276 * unbounded lifetime, i.e. objects declared 'static', but if you have a
277 * GStaticPrivate as a member of a structure and the structure is freed,
278 * you should also free the GStaticPrivate.
279 * private_key:
280 * a GStaticPrivate to be freed.
282 public void free()
284 // void g_static_private_free (GStaticPrivate *private_key);
285 g_static_private_free(gStaticPrivate);