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