Copyright | Will Thompson Iñaki García Etxebarria and Jonas Platte |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria (garetxe@gmail.com) |
Safe Haskell | None |
Language | Haskell2010 |
The GRecMutex struct is an opaque data structure to represent a
recursive mutex. It is similar to a Mutex
with the difference
that it is possible to lock a GRecMutex 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 RecMutex
is allocated in static storage then it can be used
without initialisation. Otherwise, you should call
recMutexInit
on it and recMutexClear
when done.
A GRecMutex should only be accessed with the g_rec_mutex_ functions.
Since: 2.32
Synopsis
- newtype RecMutex = RecMutex (ManagedPtr RecMutex)
- newZeroRecMutex :: MonadIO m => m RecMutex
- noRecMutex :: Maybe RecMutex
- recMutexClear :: (HasCallStack, MonadIO m) => RecMutex -> m ()
- recMutexInit :: (HasCallStack, MonadIO m) => RecMutex -> m ()
- recMutexLock :: (HasCallStack, MonadIO m) => RecMutex -> m ()
- recMutexTrylock :: (HasCallStack, MonadIO m) => RecMutex -> m Bool
- recMutexUnlock :: (HasCallStack, MonadIO m) => RecMutex -> m ()
Exported types
Memory-managed wrapper type.
Instances
WrappedPtr RecMutex Source # | |
Defined in GI.GLib.Structs.RecMutex | |
tag ~ AttrSet => Constructible RecMutex tag Source # | |
Defined in GI.GLib.Structs.RecMutex |
Methods
clear
:: (HasCallStack, MonadIO m) | |
=> RecMutex |
|
-> m () |
Frees the resources allocated to a recursive mutex with
recMutexInit
.
This function should not be used with a RecMutex
that has been
statically allocated.
Calling recMutexClear
on a locked recursive mutex leads
to undefined behaviour.
Sine: 2.32
init
:: (HasCallStack, MonadIO m) | |
=> RecMutex |
|
-> m () |
Initializes a 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.
C code
typedef struct { GRecMutex m; ... } Blob; Blob *b; b = g_new (Blob, 1); g_rec_mutex_init (&b->m);
Calling recMutexInit
on an already initialized RecMutex
leads to undefined behaviour.
To undo the effect of recMutexInit
when a recursive mutex
is no longer needed, use recMutexClear
.
Since: 2.32
lock
:: (HasCallStack, MonadIO m) | |
=> RecMutex |
|
-> m () |
Locks recMutex
. If recMutex
is already locked by another
thread, the current thread will block until recMutex
is
unlocked by the other thread. If recMutex
is already locked
by the current thread, the 'lock count' of recMutex
is increased.
The mutex will only become available again when it is unlocked
as many times as it has been locked.
Since: 2.32
trylock
unlock
:: (HasCallStack, MonadIO m) | |
=> RecMutex |
|
-> m () |
Unlocks recMutex
. If another thread is blocked in a
recMutexLock
call for recMutex
, it will become unblocked
and can lock recMutex
itself.
Calling recMutexUnlock
on a recursive mutex that is not
locked by the current thread leads to undefined behaviour.
Since: 2.32