GdaLockable

GdaLockable — Interface for locking objects in a multi threaded environment

Stability Level

Stable, unless otherwise indicated

Synopsis

                    GdaLockable;
void                gda_lockable_lock                   (GdaLockable *lockable);
gboolean            gda_lockable_trylock                (GdaLockable *lockable);
void                gda_lockable_unlock                 (GdaLockable *lockable);

Object Hierarchy

  GInterface
   +----GdaLockable

Prerequisites

GdaLockable requires GObject.

Known Implementations

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

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.

Details

GdaLockable

typedef struct _GdaLockable GdaLockable;

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).

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).

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.

lockable :

a GdaLockable object.

See Also

GdaMutex and GMutex