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  * Conversion parameters:
26  * inFile  = 
27  * outPack = gthread
28  * outFile = Private
29  * strct   = GPrivate
30  * realStrct=
31  * ctorStrct=
32  * clss    = Private
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_private_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * structWrap:
47  * module aliases:
48  * local aliases:
49  * overrides:
50  */
51 
52 module gthread.Private;
53 
54 public  import gtkc.gthreadtypes;
55 
56 private import gtkc.gthread;
57 private import glib.ConstructionException;
58 
59 
60 
61 
62 
63 
64 /**
65  * Description
66  * Threads act almost like processes, but unlike processes all threads
67  * of one process share the same memory. This is good, as it provides
68  * easy communication between the involved threads via this shared
69  * memory, and it is bad, because strange things (so called
70  * "Heisenbugs") might happen if the program is not carefully designed.
71  * In particular, due to the concurrent nature of threads, no
72  * assumptions on the order of execution of code running in different
73  * threads can be made, unless order is explicitly forced by the
74  * programmer through synchronization primitives.
75  * The aim of the thread related functions in GLib is to provide a
76  * portable means for writing multi-threaded software. There are
77  * primitives for mutexes to protect the access to portions of memory
78  * (GMutex, GStaticMutex, G_LOCK_DEFINE, GStaticRecMutex and
79  * GStaticRWLock). There are primitives for condition variables to
80  * allow synchronization of threads (GCond). There are primitives for
81  * thread-private data - data that every thread has a private instance
82  * of (GPrivate, GStaticPrivate). Last but definitely not least there
83  * are primitives to portably create and manage threads (GThread).
84  * The threading system is initialized with g_thread_init(), which
85  * takes an optional custom thread implementation or NULL for the
86  * default implementation. If you want to call g_thread_init() with a
87  * non-NULL argument this must be done before executing any other GLib
88  * functions (except g_mem_set_vtable()). This is a requirement even if
89  * no threads are in fact ever created by the process.
90  * Calling g_thread_init() with a NULL argument is somewhat more
91  * relaxed. You may call any other glib functions in the main thread
92  * before g_thread_init() as long as g_thread_init() is not called from
93  * a glib callback, or with any locks held. However, many libraries
94  * above glib does not support late initialization of threads, so doing
95  * this should be avoided if possible.
96  * Please note that since version 2.24 the GObject initialization
97  * function g_type_init() initializes threads (with a NULL argument),
98  * so most applications, including those using Gtk+ will run with
99  * threads enabled. If you want a special thread implementation, make
100  * sure you call g_thread_init() before g_type_init() is called.
101  * After calling g_thread_init(), GLib is completely thread safe (all
102  * global data is automatically locked), but individual data structure
103  * instances are not automatically locked for performance reasons. So,
104  * for example you must coordinate accesses to the same GHashTable
105  * from multiple threads. The two notable exceptions from this rule
106  * are GMainLoop and GAsyncQueue, which are
107  * threadsafe and need no further application-level locking to be
108  * accessed from multiple threads.
109  * To help debugging problems in multithreaded applications, GLib
110  * supports error-checking mutexes that will give you helpful error
111  * messages on common problems. To use error-checking mutexes, define
112  * the symbol G_ERRORCHECK_MUTEXES when compiling the application.
113  */
114 public class Private
115 {
116 	
117 	/** the main Gtk struct */
118 	protected GPrivate* gPrivate;
119 	
120 	
121 	public GPrivate* getPrivateStruct()
122 	{
123 		return gPrivate;
124 	}
125 	
126 	
127 	/** the main Gtk struct as a void* */
128 	protected void* getStruct()
129 	{
130 		return cast(void*)gPrivate;
131 	}
132 	
133 	/**
134 	 * Sets our main struct and passes it to the parent class
135 	 */
136 	public this (GPrivate* gPrivate)
137 	{
138 		this.gPrivate = gPrivate;
139 	}
140 	
141 	/**
142 	 */
143 	
144 	/**
145 	 * Creates a new GPrivate. If destructor is non-NULL, it is a
146 	 * pointer to a destructor function. Whenever a thread ends and the
147 	 * corresponding pointer keyed to this instance of GPrivate is
148 	 * non-NULL, the destructor is called with this pointer as the
149 	 * argument.
150 	 * Note
151 	 * destructor is used quite differently from notify in
152 	 * g_static_private_set().
153 	 * Note
154 	 * A GPrivate can not be freed. Reuse it instead, if you
155 	 * can, to avoid shortage, or use GStaticPrivate.
156 	 * Note
157 	 * This function will abort if g_thread_init() has not been
158 	 * called yet.
159 	 * Params:
160 	 * destructor = a function to destroy the data keyed to GPrivate when
161 	 * a thread ends.
162 	 * Throws: ConstructionException GTK+ fails to create the object.
163 	 */
164 	public this (GDestroyNotify destructor)
165 	{
166 		// GPrivate* g_private_new (GDestroyNotify destructor);
167 		auto p = g_private_new(destructor);
168 		if(p is null)
169 		{
170 			throw new ConstructionException("null returned by g_private_new(destructor)");
171 		}
172 		this(cast(GPrivate*) p);
173 	}
174 	
175 	/**
176 	 * Returns the pointer keyed to private_key for the current thread. If
177 	 * g_private_set() hasn't been called for the current private_key and
178 	 * thread yet, this pointer will be NULL.
179 	 * This function can be used even if g_thread_init() has not yet been
180 	 * called, and, in that case, will return the value of private_key
181 	 * casted to gpointer. Note however, that private data set
182 	 * before g_thread_init() will
183 	 * not be retained after the
184 	 * call. Instead, NULL will be returned in all threads directly after
185 	 * g_thread_init(), regardless of any g_private_set() calls issued
186 	 * before threading system intialization.
187 	 * Returns: the corresponding pointer.
188 	 */
189 	public void* get()
190 	{
191 		// gpointer g_private_get (GPrivate *private_key);
192 		return g_private_get(gPrivate);
193 	}
194 	
195 	/**
196 	 * Sets the pointer keyed to private_key for the current thread.
197 	 * This function can be used even if g_thread_init() has not yet been
198 	 * called, and, in that case, will set private_key to data casted to
199 	 * GPrivate*. See g_private_get() for resulting caveats.
200 	 * Params:
201 	 * data = the new pointer.
202 	 */
203 	public void set(void* data)
204 	{
205 		// void g_private_set (GPrivate *private_key,  gpointer data);
206 		g_private_set(gPrivate, data);
207 	}
208 }