mutex.c File Reference

A simple mutex in C. More...

Go to the source code of this file.

Functions

int mutex_check (MUTEX *mutex_ptr)
 Checks whether a given mutex is locked.
void mutex_lock (MUTEX *mutex_ptr)
 Locks a mutex.
void mutex_unlock (MUTEX *mutex_ptr)
 Unlocks a mutex.

Detailed Description

A simple mutex in C.

Author:
Nicolas Williamson
Date:
January 2010

Definition in file mutex.c.


Function Documentation

int mutex_check ( MUTEX *  mutex_ptr  ) 

Checks whether a given mutex is locked.

Non-blocking.

Parameters:
mutex_ptr A pointer to the mutex.
Returns:
  • 1: The mutex is locked.
  • 0: The mutex is unlocked.

Definition at line 47 of file mutex.c.

Referenced by error_occurred(), error_occurred_fiq(), error_occurred_irq(), and mutex_lock().

00047                                  {
00048   return *mutex_ptr;
00049 }

void mutex_lock ( MUTEX *  mutex_ptr  ) 

Locks a mutex.

No other process which requires this mutex may run until the mutex is unlocked. This function will block and wait until the mutex it is trying to lock is free (no other process has a lock on it).

Parameters:
mutex_ptr A pointer to the mutex.

Definition at line 25 of file mutex.c.

References mutex_check().

Referenced by error_occurred(), error_occurred_fiq(), and error_occurred_irq().

00025                                  {
00026   while (mutex_check(mutex_ptr)){} //block until mutex is unlocked
00027   *mutex_ptr = 1; //locked
00028 }

void mutex_unlock ( MUTEX *  mutex_ptr  ) 

Unlocks a mutex.

Once a process has finished executing its critical code, it should unlock the mutex to allow other processes to lock it.

Parameters:
mutex_ptr A pointer to the mutex.

Definition at line 36 of file mutex.c.

Referenced by error_occurred(), error_occurred_fiq(), and error_occurred_irq().

00036                                    {
00037   *mutex_ptr = 0; //unlocked
00038 }

Generated on Tue Jun 29 16:36:15 2010 by  doxygen 1.6.3