Mutex facilities

Name

ggLockCreate, ggLockDestroy, ggLock, ggUnlock, ggTryLock : Mutex facilities

Synopsis

#include <ggi/gg.h>

void *ggLockCreate(void);

int ggLockDestroy(void *lock);

int ggLock(void *lock);

int ggUnlock(void *lock);

int ggTryLock(void *lock);

Description

These functions allow sensitive resources protection in a threaded environmment, by ensuring exclusive access to them by a thread or process.

ggLockCreate creates a new open lock. ggLockDestroy destroys a lock.

ggLock blocks until the lock becomes available and acquire it before returning. This operation is atomic, so it guarantees that no other thread or process hold the lock after this function returns.

ggUnlock releases the lock, waking up a process that is currently waiting for this lock in ggLock.

ggTryLock attempts to acquire the lock, but unlike ggLock it will not block if the lock is not available.

Return value

ggLockCreate returns an opaque pointer to a mutex, hiding its internal implementation.

ggLock returns 0 when the lock is acquired.

ggUnlock returns 0 on success.

ggTryLock returns 0 on success, or GGI_EBUSY if the lock could not be acquired.

See Also

pthread_mutex_init(3)