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