I've no idea here...
[gtkD.git] / src / gthread / RWLock.d
blob35231679e39b1d1e938467ccf2e9ebd04bc33e0f
1 /*
2 * This file is part of duit.
4 * duit is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * duit is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with duit; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile =
26 * outPack = gthread
27 * outFile = RWLock
28 * strct = GStaticRWLock
29 * realStrct=
30 * ctorStrct=
31 * clss = RWLock
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - g_static_rw_lock_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * imports:
44 * structWrap:
45 * local aliases:
48 module gthread.RWLock;
50 private import gthread.gthreadtypes;
52 private import lib.gthread;
55 /**
56 * Description
57 * Threads act almost like processes, but unlike processes all threads of
58 * one process share the same memory. This is good, as it provides easy
59 * communication between the involved threads via this shared memory, and
60 * it is bad, because strange things (so called "Heisenbugs") might
61 * happen if the program is not carefully designed. In particular, due to
62 * the concurrent nature of threads, no assumptions on the order of
63 * execution of code running in different threads can be made, unless
64 * order is explicitly forced by the programmer through synchronization
65 * primitives.
66 * The aim of the thread related functions in GLib is to provide a
67 * portable means for writing multi-threaded software. There are
68 * primitives for mutexes to protect the access to portions of memory
69 * (GMutex, GStaticMutex, G_LOCK_DEFINE, GStaticRecMutex and
70 * GStaticRWLock). There are primitives for condition variables to allow
71 * synchronization of threads (GCond). There are primitives
72 * for thread-private data - data that every thread has a private instance of
73 * (GPrivate, GStaticPrivate). Last but definitely not least there are
74 * primitives to portably create and manage threads (GThread).
75 * You must call g_thread_init() before executing any other GLib
76 * functions in a threaded GLib program. After that, GLib is completely
77 * thread safe (all global data is automatically locked), but individual
78 * data structure instances are not automatically locked for performance
79 * reasons. So, for example you must coordinate accesses to the same
80 * GHashTable from multiple threads. The two notable exceptions from
81 * this rule are GMainLoop and GAsyncQueue,
82 * which are threadsafe and needs no further
83 * application-level locking to be accessed from multiple threads.
85 public class RWLock
88 /** the main Gtk struct */
89 protected GStaticRWLock* gStaticRWLock;
92 public GStaticRWLock* getRWLockStruct()
94 return gStaticRWLock;
98 /** the main Gtk struct as a void* */
99 protected void* getStruct()
101 return cast(void*)gStaticRWLock;
105 * Sets our main struct and passes it to the parent class
107 public this (GStaticRWLock* gStaticRWLock)
109 this.gStaticRWLock = gStaticRWLock;
166 * A GStaticRWLock must be initialized with this function before it can
167 * be used. Alternatively you can initialize it with
168 * G_STATIC_RW_LOCK_INIT.
169 * lock:
170 * a GStaticRWLock to be initialized.
172 public void init()
174 // void g_static_rw_lock_init (GStaticRWLock *lock);
175 g_static_rw_lock_init(gStaticRWLock);
179 * Locks lock for reading. There may be unlimited concurrent locks for
180 * reading of a GStaticRWLock at the same time. If lock is already
181 * locked for writing by another thread or if another thread is already
182 * waiting to lock lock for writing, this function will block until
183 * lock is unlocked by the other writing thread and no other writing
184 * threads want to lock lock. This lock has to be unlocked by
185 * g_static_rw_lock_reader_unlock().
186 * GStaticRWLock is not recursive. It might seem to be possible to
187 * recursively lock for reading, but that can result in a deadlock, due
188 * to writer preference.
189 * lock:
190 * a GStaticRWLock to lock for reading.
192 public void readerLock()
194 // void g_static_rw_lock_reader_lock (GStaticRWLock *lock);
195 g_static_rw_lock_reader_lock(gStaticRWLock);
199 * Tries to lock lock for reading. If lock is already locked for
200 * writing by another thread or if another thread is already waiting to
201 * lock lock for writing, immediately returns FALSE. Otherwise locks
202 * lock for reading and returns TRUE. This lock has to be unlocked by
203 * g_static_rw_lock_reader_unlock().
204 * lock:
205 * a GStaticRWLock to lock for reading.
206 * Returns:
207 * TRUE, if lock could be locked for reading.
209 public int readerTrylock()
211 // gboolean g_static_rw_lock_reader_trylock (GStaticRWLock *lock);
212 return g_static_rw_lock_reader_trylock(gStaticRWLock);
216 * Unlocks lock. If a thread waits to lock lock for writing and all
217 * locks for reading have been unlocked, the waiting thread is woken up
218 * and can lock lock for writing.
219 * lock:
220 * a GStaticRWLock to unlock after reading.
222 public void readerUnlock()
224 // void g_static_rw_lock_reader_unlock (GStaticRWLock *lock);
225 g_static_rw_lock_reader_unlock(gStaticRWLock);
229 * Locks lock for writing. If lock is already locked for writing or
230 * reading by other threads, this function will block until lock is
231 * completely unlocked and then lock lock for writing. While this
232 * functions waits to lock lock, no other thread can lock lock for
233 * reading. When lock is locked for writing, no other thread can lock
234 * lock (neither for reading nor writing). This lock has to be unlocked
235 * by g_static_rw_lock_writer_unlock().
236 * lock:
237 * a GStaticRWLock to lock for writing.
239 public void writerLock()
241 // void g_static_rw_lock_writer_lock (GStaticRWLock *lock);
242 g_static_rw_lock_writer_lock(gStaticRWLock);
246 * Tries to lock lock for writing. If lock is already locked (for
247 * either reading or writing) by another thread, it immediately returns
248 * FALSE. Otherwise it locks lock for writing and returns TRUE. This
249 * lock has to be unlocked by g_static_rw_lock_writer_unlock().
250 * lock:
251 * a GStaticRWLock to lock for writing.
252 * Returns:
253 * TRUE, if lock could be locked for writing.
255 public int writerTrylock()
257 // gboolean g_static_rw_lock_writer_trylock (GStaticRWLock *lock);
258 return g_static_rw_lock_writer_trylock(gStaticRWLock);
262 * Unlocks lock. If a thread is waiting to lock lock for writing and
263 * all locks for reading have been unlocked, the waiting thread is woken
264 * up and can lock lock for writing. If no thread is waiting to lock
265 * lock for writing, and some thread or threads are waiting to lock lock
266 * for reading, the waiting threads are woken up and can lock lock for
267 * reading.
268 * lock:
269 * a GStaticRWLock to unlock after writing.
271 public void writerUnlock()
273 // void g_static_rw_lock_writer_unlock (GStaticRWLock *lock);
274 g_static_rw_lock_writer_unlock(gStaticRWLock);
278 * Releases all resources allocated to lock.
279 * You don't have to call this functions for a GStaticRWLock with an
280 * unbounded lifetime, i.e. objects declared 'static', but if you have a
281 * GStaticRWLock as a member of a structure, and the structure is freed,
282 * you should also free the GStaticRWLock.
283 * lock:
284 * a GStaticRWLock to be freed.
286 public void free()
288 // void g_static_rw_lock_free (GStaticRWLock *lock);
289 g_static_rw_lock_free(gStaticRWLock);