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