source: appstream-generator/build/girepo/glib/RecMutex.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

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