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