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