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