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.RecMutex; 26 27 private import glib.c.functions; 28 public import glib.c.types; 29 public import gtkc.glibtypes; 30 31 32 /** 33 * The GRecMutex struct is an opaque data structure to represent a 34 * recursive mutex. It is similar to a #GMutex with the difference 35 * that it is possible to lock a GRecMutex multiple times in the same 36 * thread without deadlock. When doing so, care has to be taken to 37 * unlock the recursive mutex as often as it has been locked. 38 * 39 * If a #GRecMutex is allocated in static storage then it can be used 40 * without initialisation. Otherwise, you should call 41 * g_rec_mutex_init() on it and g_rec_mutex_clear() when done. 42 * 43 * A GRecMutex should only be accessed with the 44 * g_rec_mutex_ functions. 45 * 46 * Since: 2.32 47 */ 48 public class RecMutex 49 { 50 /** the main Gtk struct */ 51 protected GRecMutex* gRecMutex; 52 protected bool ownedRef; 53 54 /** Get the main Gtk struct */ 55 public GRecMutex* getRecMutexStruct(bool transferOwnership = false) 56 { 57 if (transferOwnership) 58 ownedRef = false; 59 return gRecMutex; 60 } 61 62 /** the main Gtk struct as a void* */ 63 protected void* getStruct() 64 { 65 return cast(void*)gRecMutex; 66 } 67 68 /** 69 * Sets our main struct and passes it to the parent class. 70 */ 71 public this (GRecMutex* gRecMutex, bool ownedRef = false) 72 { 73 this.gRecMutex = gRecMutex; 74 this.ownedRef = ownedRef; 75 } 76 77 78 /** 79 * Frees the resources allocated to a recursive mutex with 80 * g_rec_mutex_init(). 81 * 82 * This function should not be used with a #GRecMutex that has been 83 * statically allocated. 84 * 85 * Calling g_rec_mutex_clear() on a locked recursive mutex leads 86 * to undefined behaviour. 87 * 88 * Sine: 2.32 89 */ 90 public void clear() 91 { 92 g_rec_mutex_clear(gRecMutex); 93 } 94 95 /** 96 * Initializes a #GRecMutex so that it can be used. 97 * 98 * This function is useful to initialize a recursive mutex 99 * that has been allocated on the stack, or as part of a larger 100 * structure. 101 * 102 * It is not necessary to initialise a recursive mutex that has been 103 * statically allocated. 104 * 105 * |[<!-- language="C" --> 106 * typedef struct { 107 * GRecMutex m; 108 * ... 109 * } Blob; 110 * 111 * Blob *b; 112 * 113 * b = g_new (Blob, 1); 114 * g_rec_mutex_init (&b->m); 115 * ]| 116 * 117 * Calling g_rec_mutex_init() on an already initialized #GRecMutex 118 * leads to undefined behaviour. 119 * 120 * To undo the effect of g_rec_mutex_init() when a recursive mutex 121 * is no longer needed, use g_rec_mutex_clear(). 122 * 123 * Since: 2.32 124 */ 125 public void init() 126 { 127 g_rec_mutex_init(gRecMutex); 128 } 129 130 /** 131 * Locks @rec_mutex. If @rec_mutex is already locked by another 132 * thread, the current thread will block until @rec_mutex is 133 * unlocked by the other thread. If @rec_mutex is already locked 134 * by the current thread, the 'lock count' of @rec_mutex is increased. 135 * The mutex will only become available again when it is unlocked 136 * as many times as it has been locked. 137 * 138 * Since: 2.32 139 */ 140 public void lock() 141 { 142 g_rec_mutex_lock(gRecMutex); 143 } 144 145 /** 146 * Tries to lock @rec_mutex. If @rec_mutex is already locked 147 * by another thread, it immediately returns %FALSE. Otherwise 148 * it locks @rec_mutex and returns %TRUE. 149 * 150 * Returns: %TRUE if @rec_mutex could be locked 151 * 152 * Since: 2.32 153 */ 154 public bool trylock() 155 { 156 return g_rec_mutex_trylock(gRecMutex) != 0; 157 } 158 159 /** 160 * Unlocks @rec_mutex. If another thread is blocked in a 161 * g_rec_mutex_lock() call for @rec_mutex, it will become unblocked 162 * and can lock @rec_mutex itself. 163 * 164 * Calling g_rec_mutex_unlock() on a recursive mutex that is not 165 * locked by the current thread leads to undefined behaviour. 166 * 167 * Since: 2.32 168 */ 169 public void unlock() 170 { 171 g_rec_mutex_unlock(gRecMutex); 172 } 173 }