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