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 glib.Once;
26 
27 private import glib.MemorySlice;
28 private import glib.c.functions;
29 public  import glib.c.types;
30 private import gtkd.Loader;
31 
32 
33 /**
34  * A #GOnce struct controls a one-time initialization function. Any
35  * one-time initialization function must have its own unique #GOnce
36  * struct.
37  *
38  * Since: 2.4
39  */
40 public final class Once
41 {
42 	/** the main Gtk struct */
43 	protected GOnce* gOnce;
44 	protected bool ownedRef;
45 
46 	/** Get the main Gtk struct */
47 	public GOnce* getOnceStruct(bool transferOwnership = false)
48 	{
49 		if (transferOwnership)
50 			ownedRef = false;
51 		return gOnce;
52 	}
53 
54 	/** the main Gtk struct as a void* */
55 	protected void* getStruct()
56 	{
57 		return cast(void*)gOnce;
58 	}
59 
60 	/**
61 	 * Sets our main struct and passes it to the parent class.
62 	 */
63 	public this (GOnce* gOnce, bool ownedRef = false)
64 	{
65 		this.gOnce = gOnce;
66 		this.ownedRef = ownedRef;
67 	}
68 
69 	~this ()
70 	{
71 		if ( Linker.isLoaded(LIBRARY_GLIB) && ownedRef )
72 			sliceFree(gOnce);
73 	}
74 
75 
76 	/**
77 	 * the status of the #GOnce
78 	 */
79 	public @property GOnceStatus status()
80 	{
81 		return gOnce.status;
82 	}
83 
84 	/** Ditto */
85 	public @property void status(GOnceStatus value)
86 	{
87 		gOnce.status = value;
88 	}
89 
90 	/**
91 	 * the value returned by the call to the function, if @status
92 	 * is %G_ONCE_STATUS_READY
93 	 */
94 	public @property void* retval()
95 	{
96 		return gOnce.retval;
97 	}
98 
99 	/** Ditto */
100 	public @property void retval(void* value)
101 	{
102 		gOnce.retval = value;
103 	}
104 
105 	/** */
106 	public void* impl(GThreadFunc func, void* arg)
107 	{
108 		return g_once_impl(gOnce, func, arg);
109 	}
110 
111 	/**
112 	 * Function to be called when starting a critical initialization
113 	 * section. The argument @location must point to a static
114 	 * 0-initialized variable that will be set to a value other than 0 at
115 	 * the end of the initialization section. In combination with
116 	 * g_once_init_leave() and the unique address @value_location, it can
117 	 * be ensured that an initialization section will be executed only once
118 	 * during a program's life time, and that concurrent threads are
119 	 * blocked until initialization completed. To be used in constructs
120 	 * like this:
121 	 *
122 	 * |[<!-- language="C" -->
123 	 * static gsize initialization_value = 0;
124 	 *
125 	 * if (g_once_init_enter (&initialization_value))
126 	 * {
127 	 * gsize setup_value = 42; // initialization code here
128 	 *
129 	 * g_once_init_leave (&initialization_value, setup_value);
130 	 * }
131 	 *
132 	 * // use initialization_value here
133 	 * ]|
134 	 *
135 	 * While @location has a `volatile` qualifier, this is a historical artifact and
136 	 * the pointer passed to it should not be `volatile`.
137 	 *
138 	 * Params:
139 	 *     location = location of a static initializable variable
140 	 *         containing 0
141 	 *
142 	 * Returns: %TRUE if the initialization section should be entered,
143 	 *     %FALSE and blocks otherwise
144 	 *
145 	 * Since: 2.14
146 	 */
147 	public static bool initEnter(void* location)
148 	{
149 		return g_once_init_enter(location) != 0;
150 	}
151 
152 	/**
153 	 * Counterpart to g_once_init_enter(). Expects a location of a static
154 	 * 0-initialized initialization variable, and an initialization value
155 	 * other than 0. Sets the variable to the initialization value, and
156 	 * releases concurrent threads blocking in g_once_init_enter() on this
157 	 * initialization variable.
158 	 *
159 	 * While @location has a `volatile` qualifier, this is a historical artifact and
160 	 * the pointer passed to it should not be `volatile`.
161 	 *
162 	 * Params:
163 	 *     location = location of a static initializable variable
164 	 *         containing 0
165 	 *     result = new non-0 value for *@value_location
166 	 *
167 	 * Since: 2.14
168 	 */
169 	public static void initLeave(void* location, size_t result)
170 	{
171 		g_once_init_leave(location, result);
172 	}
173 }