locks.h File Reference

Go to the source code of this file.

Data Structures

struct  semaphore_t
struct  mutex_t

Functions

semaphore_t semaphores_create (int count)
 Creates a semaphore.
void semaphores_lock (semaphore_t *s)
 Locks a semaphore.
int semaphores_lock_noblock (semaphore_t *s)
 Locks a semaphore.
void semaphores_unlock (semaphore_t *s)
 Unlocks a semaphore.
mutex_t mutexes_create (void)
 Creates a mutex.
void mutexes_lock (mutex_t *m)
 Locks a mutex.
int mutexes_lock_noblock (mutex_t *m)
 Locks a mutex.
void mutexes_unlock (mutex_t *m)
 Unlocks a mutex.

Detailed Description

Locking API for libthreads.

Todo:
Semaphores and mutexes should have a queue of threads that are waiting for a lock, then wake one whenever the lock is unlocked. (thanks tueidj)

Function Documentation

mutex_t mutexes_create ( void   ) 

Creates a mutex.

Returns:
A mutex object.
void mutexes_lock ( mutex_t m  ) 

Locks a mutex.

This call is BLOCKING, using sleep mode. Do not use this function inside of an interrupt handler, nor within a threads_freeze() block.

Parameters:
m a pointer to the mutex to lock.
See also:
mutexes_lock_noblock(), mutexes_unlock()
int mutexes_lock_noblock ( mutex_t m  ) 

Locks a mutex.

This call is nonblocking, thus it is safe to use within an interrupt handler or a threads_freeze() block. It will return no matter whether it succeeded or failed.

Parameters:
m a pointer to the mutex to lock.
Returns:
1 if the mutex was able to be locked, 0 if it was not.
See also:
mutexes_lock(), mutexes_unlock()
void mutexes_unlock ( mutex_t m  ) 

Unlocks a mutex.

Parameters:
m a pointer to the mutex to unlock.
See also:
mutexes_lock_noblock(), mutexes_lock()
semaphore_t semaphores_create ( int  count  ) 

Creates a semaphore.

Parameters:
count how many locks the semaphore may take before waiting.
Returns:
A semaphore object with the requested specification.
void semaphores_lock ( semaphore_t s  ) 

Locks a semaphore.

This call is BLOCKING, using sleep mode. Do not use this function inside of an interrupt handler, nor within a threads_freeze() block.

Parameters:
s a pointer to the semaphore to lock.
See also:
semaphores_lock_noblock(), semaphores_unlock()
int semaphores_lock_noblock ( semaphore_t s  ) 

Locks a semaphore.

This call is nonblocking, thus it is safe to use within an interrupt handler or a threads_freeze() block. It will return no matter whether it succeeded or failed.

Parameters:
s a pointer to the semaphore to lock.
Returns:
1 if the semaphore was able to be locked, 0 if it was not.
See also:
semaphores_lock(), semaphores_unlock()
void semaphores_unlock ( semaphore_t s  ) 

Unlocks a semaphore.

Unlocks a semaphore by a single level.

Parameters:
s a pointer to the semaphore to unlock.
See also:
semaphores_lock_noblock(), semaphores_lock()
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines
Generated by  doxygen 1.6.3