GLib.RecMutex¶
Fields¶
Name |
Type |
Access |
Description |
---|---|---|---|
i |
[ |
r |
|
p |
r |
Methods¶
|
|
|
|
|
|
|
|
|
Details¶
- class GLib.RecMutex¶
The
GLib.RecMutex
struct is an opaque data structure to represent a recursive mutex. It is similar to aGLib.Mutex
with the difference that it is possible to lock aGLib.RecMutex
multiple times in the same thread without deadlock. When doing so, care has to be taken to unlock the recursive mutex as often as it has been locked.If a
GLib.RecMutex
is allocated in static storage then it can be used without initialisation. Otherwise, you should callGLib.RecMutex.init
() on it andGLib.RecMutex.clear
() when done.A
GLib.RecMutex
should only be accessed with the g_rec_mutex_ functions.New in version 2.32.
- clear()[source]¶
Frees the resources allocated to a recursive mutex with
GLib.RecMutex.init
().This function should not be used with a
GLib.RecMutex
that has been statically allocated.Calling
GLib.RecMutex.clear
() on a locked recursive mutex leads to undefined behaviour.New in version 2.32.
- init()[source]¶
Initializes a
GLib.RecMutex
so that it can be used.This function is useful to initialize a recursive mutex that has been allocated on the stack, or as part of a larger structure.
It is not necessary to initialise a recursive mutex that has been statically allocated.
typedef struct { GRecMutex m; ... } Blob; Blob *b; b = g_new (Blob, 1); g_rec_mutex_init (&b->m);
Calling
GLib.RecMutex.init
() on an already initializedGLib.RecMutex
leads to undefined behaviour.To undo the effect of
GLib.RecMutex.init
() when a recursive mutex is no longer needed, useGLib.RecMutex.clear
().New in version 2.32.
- lock()[source]¶
Locks self. If self is already locked by another thread, the current thread will block until self is unlocked by the other thread. If self is already locked by the current thread, the ‘lock count’ of self is increased. The mutex will only become available again when it is unlocked as many times as it has been locked.
New in version 2.32.
- trylock()[source]¶
-
Tries to lock self. If self is already locked by another thread, it immediately returns
False
. Otherwise it locks self and returnsTrue
.New in version 2.32.
- unlock()[source]¶
Unlocks self. If another thread is blocked in a
GLib.RecMutex.lock
() call for self, it will become unblocked and can lock self itself.Calling
GLib.RecMutex.unlock
() on a recursive mutex that is not locked by the current thread leads to undefined behaviour.New in version 2.32.