## GdaLockable

GdaLockable — Interface for locking objects in a multi threaded environment

## Stability Level

Stable, unless otherwise indicated

## Functions

void | gda_lockable_lock ()
gboolean | gda_lockable_trylock ()
void | gda_lockable_unlock ()

## Types and Values

| GdaLockable

## Object Hierarchy

        GInterface
        ╰── GdaLockable

## Prerequisites

GdaLockable requires GObject.

## Known Implementations

GdaLockable is implemented by GdaConnection, GdaHolder, GdaSqlParser, GdaVconnectionDataModel, GdaVconnectionHub and GdaVirtualConnection.

## Includes

    #include <libgda/gda-statement-extra.h>

## Description

This interface is implemented by objects which are thread safe (ie. can be used by several threads at the same time). Before using an object from a thread, one has to call `gda_lockable_lock()` or `gda_lockable_trylock()` and call `gda_lockable_unlock()` when the object is not used anymore.

## Functions

### gda_lockable_lock ()

    void
    gda_lockable_lock (GdaLockable *lockable);

Locks `lockable` . If it is already locked by another thread, the current thread will block until it 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()`, this method recursive, which means a thread can lock `lockable` several times (and has to unlock it as many times to actually unlock it).

#### Parameters

lockable | a GdaLockable object. |

### gda_lockable_trylock ()

    gboolean
    gda_lockable_trylock (GdaLockable *lockable);

Tries to lock `lockable` . If it is already locked by another thread, then it immediately returns FALSE, otherwise it locks `lockable` .

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()`, this method recursive, which means a thread can lock `lockable` several times (and has to unlock it as many times to actually unlock it).

#### Parameters

lockable | a GdaLockable object. |

#### Returns

TRUE if the object has successfully been locked.

### gda_lockable_unlock ()

    void
    gda_lockable_unlock (GdaLockable *lockable);

Unlocks `lockable` . This method should not be called if the current does not already holds a lock on `lockable` (having used `gda_lockable_lock()` or `gda_lockable_trylock()`).

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

#### Parameters

lockable | a GdaLockable object. |

## Types and Values

### GdaLockable

    typedef struct _GdaLockable GdaLockable;

## See Also

GdaMutex and GMutex