# Unnamed semaphores

Unnamed semaphores.

Summary

Unnamed semaphores | Unnamed semaphores.
Types |
nacore_sem | Semaphore.
Functions |
nacore_sem_new() | Creates a new semaphore.
nacore_sem_free() | Destroys a semaphore.
nacore_sem_wait() | Locks a semaphore.
nacore_sem_trywait() | Attempts to lock a semaphore.
nacore_sem_post() | Unlocks a semaphore.

### Types

### nacore_sem

Semaphore.

### Functions

### nacore_sem_new()

> _NACORE_DEF nacore_sem nacore_sem_new( | unsigned | int | value | )

Creates a new semaphore.

#### Parameters

value | Initial value.

#### Returns

The newly created semaphore or NULL if some error occured, in which case errno is set to ENOMEM if there was not enough memory, EINVAL if value is too big or NACORE_EUNKNOWN if another kind of error happened.

### nacore_sem_free()

> _NACORE_DEF void nacore_sem_free( | nacore_sem | sem | )

Destroys a semaphore.

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

#### Parameters

sem | The semaphore to be destroyed.

### nacore_sem_wait()

> _NACORE_DEF int nacore_sem_wait( | nacore_sem | sem | )

Locks a semaphore.

#### Parameters

sem | The sempahore to be locked.

#### Returns

0 on success or EINTR if the call was interrupted by a signal.

### nacore_sem_trywait()

> _NACORE_DEF int nacore_sem_trywait( | nacore_sem | sem | )

Attempts to lock a semaphore.

If the semaphore is already locked the call shall return immediately.

#### Parameters

sem | The semaphore to be locked.

#### Returns

0 on success, EAGAIN if the semaphore was already locked or EINTR if the call was interrupted by a signal.

### nacore_sem_post()

> _NACORE_DEF int nacore_sem_post( | nacore_sem | sem | )

Unlocks a semaphore.

#### Parameters

sem | The semaphore to be unlocked.

#### Returns

0 on success or NACORE_EUNKNOWN if some error happened.

> _NACORE_DEF nacore_sem nacore_sem_new( | unsigned | int | value | )

Creates a new semaphore.

> _NACORE_DEF void nacore_sem_free( | nacore_sem | sem | )

Destroys a semaphore.

> _NACORE_DEF int nacore_sem_wait( | nacore_sem | sem | )

Locks a semaphore.

> _NACORE_DEF int nacore_sem_trywait( | nacore_sem | sem | )

Attempts to lock a semaphore.

> _NACORE_DEF int nacore_sem_post( | nacore_sem | sem | )

Unlocks a semaphore.
Error code for unknown errors.
Close