# Mutexes

Mutexes with deadlock checking.

Summary

Mutexes | Mutexes with deadlock checking.
Types |
nacore_mutex | Mutex.
Functions |
nacore_mutex_new() | Creates a new mutex.
nacore_mutex_free() | Destroys a mutex.
nacore_mutex_lock() | Acquires the lock on a mutex.
nacore_mutex_trylock() | Attempts to acquire the lock on a mutex.
nacore_mutex_unlock() | Releases the lock on a mutex.

### Types

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

Destroys a mutex.

Once this function is called, referring to mutex will cause undefined behavior.

#### Parameters

mutex | The 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

mutex | The 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 mutex.

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

#### Parameters

mutex | The 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 mutex.

#### Parameters

mutex | The mutex on which the lock is to be released.

> _NACORE_DEF nacore_mutex nacore_mutex_new()

Creates a new mutex.

> _NACORE_DEF void nacore_mutex_free( | nacore_mutex | mutex | )

Destroys 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 mutex.

> _NACORE_DEF void nacore_mutex_unlock( | nacore_mutex | mutex | )

Releases the lock on a mutex.
Error code for unknown errors.
Close