## GdaMutex

GdaMutex — Recursive mutex implementation

## Stability Level

Stable, unless otherwise indicated

## Functions

GdaMutex * | gda_mutex_new ()
void | gda_mutex_lock ()
gboolean | gda_mutex_trylock ()
void | gda_mutex_unlock ()
void | gda_mutex_free ()

## Types and Values

typedef | GdaMutex

## Includes

    #include <virtual/gda-ldap-connection.h>

## Description

GdaMutex implements a recursive mutex (unlike the GMutex implementation which offers no guarantee about recursiveness). A recursive mutex is a mutex which can be locked several times by the same thread (and needs to be unlocked the same number of times before another thread can lock it).

A GdaMutex can safely be used even in a non multi-threaded environment in which case it does nothing.

## Functions

### gda_mutex_new ()

    GdaMutex *
    gda_mutex_new (void);

`gda_mutex_new` has been deprecated since version 5.2.0 and should not be used in newly-written code.

use GRecMutex instead.

Creates a new GdaMutex.

#### Returns

a new GdaMutex.

[transfer full]

### gda_mutex_lock ()

    void
    gda_mutex_lock (GdaMutex *mutex);

`gda_mutex_lock` has been deprecated since version 5.2.0 and should not be used in newly-written code.

use GRecMutex instead.

Locks `mutex` . If `mutex` is already locked by another thread, the current thread will block until `mutex` is unlocked by the other thread.

This function can be used even if `g_thread_init()` has not yet been called, and, in that case, will do nothing.

Note: unlike `g_mutex_lock()`, the GdaMutex is recursive, which means a thread can lock it several times (and has to unlock it as many times to actually unlock it).

#### Parameters

mutex | a GdaMutex |

### gda_mutex_trylock ()

    gboolean
    gda_mutex_trylock (GdaMutex *mutex);

`gda_mutex_trylock` has been deprecated since version 5.2.0 and should not be used in newly-written code.

use GRecMutex instead.

Tries to lock `mutex` . If `mutex` is already locked by another thread, it immediately returns FALSE. Otherwise it locks `mutex` and returns TRUE

This function can be used even if `g_thread_init()` has not yet been called, and, in that case, will immediately return TRUE.

Note: Unlike `g_mutex_trylock()`, the GdaMutex is recursive, which means a thread can lock it several times (and has to unlock it as many times to actually unlock it)

#### Parameters

mutex | a GdaMutex |

#### Returns

TRUE, if `mutex` could be locked.

### gda_mutex_unlock ()

    void
    gda_mutex_unlock (GdaMutex *mutex);

`gda_mutex_unlock` has been deprecated since version 5.2.0 and should not be used in newly-written code.

use GRecMutex instead.

Unlocks `mutex` . If another thread is blocked in a `gda_mutex_lock()` call for `mutex` , it wil be woken and can lock `mutex` itself. This function can be used even if `g_thread_init()` has not yet been called, and, in that case, will do nothing.

#### Parameters

mutex | a GdaMutex |

### gda_mutex_free ()

    void
    gda_mutex_free (GdaMutex *mutex);

`gda_mutex_free` has been deprecated since version 5.2.0 and should not be used in newly-written code.

use GRecMutex instead.

Destroys `mutex` .

#### Parameters

mutex | a GdaMutex. | [transfer full]

## Types and Values

### GdaMutex

    typedef GRecMutex GdaMutex;

## See Also

GdaLockable and GMutex