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