Mutexes

Mutexes with deadlock checking.

Summary
MutexesMutexes with deadlock checking.
Types
nacore_mutexMutex.
Functions
nacore_mutex_new()Creates a new mutex.
nacore_mutex_free()Destroies a mutex.
nacore_mutex_lock()Acquires the lock on a mutex.
nacore_mutex_trylock()Attempts to acquire the lock on a recursive mutex.
nacore_mutex_unlock()Releases the lock on a recursive mutex.

Types

nacore_mutex

typedef struct _nacore_mutex *nacore_mutex

Mutex.

Functions

nacore_mutex_new()

_NACORE_DEF nacore_mutex nacore_mutex_new()

Creates a new mutex.

Returns

The newly creted mutex or NULL if some error occurred, in which case errno is set to EAGAIN if the system lacked the necessary resources (other than memory), ENOMEM if there was not enough memory, EPERM if the caller does not have the priviledge to perform the operation or NACORE_EUNKNOWN if another kind of error happened.

nacore_mutex_free()

_NACORE_DEF void nacore_mutex_free(nacore_mutex mutex)

Destroies a mutex.

Parameters

mutexThe mutex to be destroyed.

nacore_mutex_lock()

_NACORE_DEF int nacore_mutex_lock(nacore_mutex mutex)

Acquires the lock on a mutex.

If the mutex is locked by some other thread, the calling thread shall block until the mutex becomes available.

Parameters

mutexThe mutex to acquire the lock on.

Returns

0 on success or EDEADLK if the current thread already owns the mutex.

nacore_mutex_trylock()

_NACORE_DEF int nacore_mutex_trylock(nacore_mutex mutex)

Attempts to acquire the lock on a recursive mutex.

If the mutex is already locked by any thread, including the current thread, the call shall return immediately.

Parameters

mutexThe mutex to acquire the lock on.

Returns

0 on success or EBUSY if the lock couldn’t be acquired because it was already locked.

nacore_mutex_unlock()

_NACORE_DEF void nacore_mutex_unlock(nacore_mutex mutex)

Releases the lock on a recursive mutex.

Parameters

mutexThe mutex on which the lock is to be released.
typedef struct _nacore_mutex *nacore_mutex
Mutex.
_NACORE_DEF nacore_mutex nacore_mutex_new()
Creates a new mutex.
_NACORE_DEF void nacore_mutex_free(nacore_mutex mutex)
Destroies a mutex.
_NACORE_DEF int nacore_mutex_lock(nacore_mutex mutex)
Acquires the lock on a mutex.
_NACORE_DEF int nacore_mutex_trylock(nacore_mutex mutex)
Attempts to acquire the lock on a recursive mutex.
_NACORE_DEF void nacore_mutex_unlock(nacore_mutex mutex)
Releases the lock on a recursive mutex.
Error code for unknown errors.
Close