gi-glib-2.0.24: GLib bindings
CopyrightWill Thompson Iñaki García Etxebarria and Jonas Platte
LicenseLGPL-2.1
MaintainerIñaki García Etxebarria
Safe HaskellNone
LanguageHaskell2010

GI.GLib.Structs.RecMutex

Description

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

Exported types

newtype RecMutex Source #

Memory-managed wrapper type.

Constructors

RecMutex (ManagedPtr RecMutex) 

Instances

Instances details
Eq RecMutex Source # 
Instance details

Defined in GI.GLib.Structs.RecMutex

ManagedPtrNewtype RecMutex Source # 
Instance details

Defined in GI.GLib.Structs.RecMutex

BoxedPtr RecMutex Source # 
Instance details

Defined in GI.GLib.Structs.RecMutex

CallocPtr RecMutex Source # 
Instance details

Defined in GI.GLib.Structs.RecMutex

tag ~ 'AttrSet => Constructible RecMutex tag Source # 
Instance details

Defined in GI.GLib.Structs.RecMutex

Methods

new :: MonadIO m => (ManagedPtr RecMutex -> RecMutex) -> [AttrOp RecMutex tag] -> m RecMutex #

newZeroRecMutex :: MonadIO m => m RecMutex Source #

Construct a RecMutex struct initialized to zero.

Methods

Overloaded methods

clear

recMutexClear Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> RecMutex

recMutex: an initialized 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

recMutexInit Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> RecMutex

recMutex: an uninitialized 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

recMutexLock Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> RecMutex

recMutex: a 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

recMutexTrylock Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> RecMutex

recMutex: a RecMutex

-> m Bool

Returns: True if recMutex could be locked

Tries to lock recMutex. If recMutex is already locked by another thread, it immediately returns False. Otherwise it locks recMutex and returns True.

Since: 2.32

unlock

recMutexUnlock Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> RecMutex

recMutex: a 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