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