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 * Conversion parameters: 26 * inFile = 27 * outPack = gthread 28 * outFile = StaticMutex 29 * strct = GStaticMutex 30 * realStrct= 31 * ctorStrct= 32 * clss = StaticMutex 33 * interf = 34 * class Code: Yes 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - g_static_mutex_ 41 * omit structs: 42 * omit prefixes: 43 * omit code: 44 * omit signals: 45 * imports: 46 * - gthread.Mutex 47 * structWrap: 48 * - GMutex* -> Mutex 49 * module aliases: 50 * local aliases: 51 * overrides: 52 */ 53 54 module gthread.StaticMutex; 55 56 public import gtkc.gthreadtypes; 57 58 private import gtkc.gthread; 59 private import glib.ConstructionException; 60 61 62 private import gthread.Mutex; 63 64 65 66 67 /** 68 * Description 69 * Threads act almost like processes, but unlike processes all threads 70 * of one process share the same memory. This is good, as it provides 71 * easy communication between the involved threads via this shared 72 * memory, and it is bad, because strange things (so called 73 * "Heisenbugs") might happen if the program is not carefully designed. 74 * In particular, due to the concurrent nature of threads, no 75 * assumptions on the order of execution of code running in different 76 * threads can be made, unless order is explicitly forced by the 77 * programmer through synchronization primitives. 78 * The aim of the thread related functions in GLib is to provide a 79 * portable means for writing multi-threaded software. There are 80 * primitives for mutexes to protect the access to portions of memory 81 * (GMutex, GStaticMutex, G_LOCK_DEFINE, GStaticRecMutex and 82 * GStaticRWLock). There are primitives for condition variables to 83 * allow synchronization of threads (GCond). There are primitives for 84 * thread-private data - data that every thread has a private instance 85 * of (GPrivate, GStaticPrivate). Last but definitely not least there 86 * are primitives to portably create and manage threads (GThread). 87 * The threading system is initialized with g_thread_init(), which 88 * takes an optional custom thread implementation or NULL for the 89 * default implementation. If you want to call g_thread_init() with a 90 * non-NULL argument this must be done before executing any other GLib 91 * functions (except g_mem_set_vtable()). This is a requirement even if 92 * no threads are in fact ever created by the process. 93 * Calling g_thread_init() with a NULL argument is somewhat more 94 * relaxed. You may call any other glib functions in the main thread 95 * before g_thread_init() as long as g_thread_init() is not called from 96 * a glib callback, or with any locks held. However, many libraries 97 * above glib does not support late initialization of threads, so doing 98 * this should be avoided if possible. 99 * Please note that since version 2.24 the GObject initialization 100 * function g_type_init() initializes threads (with a NULL argument), 101 * so most applications, including those using Gtk+ will run with 102 * threads enabled. If you want a special thread implementation, make 103 * sure you call g_thread_init() before g_type_init() is called. 104 * After calling g_thread_init(), GLib is completely thread safe (all 105 * global data is automatically locked), but individual data structure 106 * instances are not automatically locked for performance reasons. So, 107 * for example you must coordinate accesses to the same GHashTable 108 * from multiple threads. The two notable exceptions from this rule 109 * are GMainLoop and GAsyncQueue, which are 110 * threadsafe and need no further application-level locking to be 111 * accessed from multiple threads. 112 * To help debugging problems in multithreaded applications, GLib 113 * supports error-checking mutexes that will give you helpful error 114 * messages on common problems. To use error-checking mutexes, define 115 * the symbol G_ERRORCHECK_MUTEXES when compiling the application. 116 */ 117 public class StaticMutex 118 { 119 120 /** the main Gtk struct */ 121 protected GStaticMutex* gStaticMutex; 122 123 124 public GStaticMutex* getStaticMutexStruct() 125 { 126 return gStaticMutex; 127 } 128 129 130 /** the main Gtk struct as a void* */ 131 protected void* getStruct() 132 { 133 return cast(void*)gStaticMutex; 134 } 135 136 /** 137 * Sets our main struct and passes it to the parent class 138 */ 139 public this (GStaticMutex* gStaticMutex) 140 { 141 this.gStaticMutex = gStaticMutex; 142 } 143 144 /** 145 * Creates a new initialized StaticMutex. 146 */ 147 public this () 148 { 149 this(new GStaticMutex); 150 151 init(); 152 } 153 154 /** 155 */ 156 157 /** 158 * Initializes mutex. Alternatively you can initialize it with 159 * G_STATIC_MUTEX_INIT. 160 */ 161 public void init() 162 { 163 // void g_static_mutex_init (GStaticMutex *mutex); 164 g_static_mutex_init(gStaticMutex); 165 } 166 167 /** 168 * Works like g_mutex_lock(), but for a GStaticMutex. 169 */ 170 public void lock() 171 { 172 // void g_static_mutex_lock (GStaticMutex *mutex); 173 g_static_mutex_lock(gStaticMutex); 174 } 175 176 /** 177 * Works like g_mutex_trylock(), but for a GStaticMutex. 178 * Returns: TRUE, if the GStaticMutex could be locked. 179 */ 180 public int trylock() 181 { 182 // gboolean g_static_mutex_trylock (GStaticMutex *mutex); 183 return g_static_mutex_trylock(gStaticMutex); 184 } 185 186 /** 187 * Works like g_mutex_unlock(), but for a GStaticMutex. 188 */ 189 public void unlock() 190 { 191 // void g_static_mutex_unlock (GStaticMutex *mutex); 192 g_static_mutex_unlock(gStaticMutex); 193 } 194 195 /** 196 * For some operations (like g_cond_wait()) you must have a GMutex 197 * instead of a GStaticMutex. This function will return the 198 * corresponding GMutex for mutex. 199 * Returns: the GMutex corresponding to mutex. 200 */ 201 public Mutex getMutex() 202 { 203 // GMutex * g_static_mutex_get_mutex (GStaticMutex *mutex); 204 auto p = g_static_mutex_get_mutex(gStaticMutex); 205 206 if(p is null) 207 { 208 return null; 209 } 210 211 return new Mutex(cast(GMutex*) p); 212 } 213 214 /** 215 * Releases all resources allocated to mutex. 216 * You don't have to call this functions for a GStaticMutex with an 217 * unbounded lifetime, i.e. objects declared 'static', but if you have 218 * a GStaticMutex as a member of a structure and the structure is 219 * freed, you should also free the GStaticMutex. 220 * Note 221 * Calling g_static_mutex_free() on a locked mutex may 222 * result in undefined behaviour. 223 */ 224 public void free() 225 { 226 // void g_static_mutex_free (GStaticMutex *mutex); 227 g_static_mutex_free(gStaticMutex); 228 } 229 }