Chris O'Byrne - YAVRTOS

Mutexes


Functions

uint8_t lock_on (mutex_t *m)
 Lock on a mutex.
uint8_t lock_off (mutex_t *m)
 Unlock a mutex.

Detailed Description

A MUTual EXclusion object - only one task can "own" a mutex at any one time.

Mutexes are "owned" by calling lock_on(), and released by calling lock_off()

If another task tries to own an "owned" mutex, that task will be suspended until the mutex becomes available.

Tasks may own as many mutexes as they wish, and mutexes will automatically be released when the task exits

See using mutexes for information on how to use mutexes

If malloc() is going to be used by your task, then you may require a mutex for the microcontroller memory - see How do I use malloc() and free() safely?


Function Documentation

uint8_t lock_off ( mutex_t m  ) 

Unlock a mutex.

This function can only usefully be called by the task that locked the mutex in the first place, and it may end up yielding control to a task that is waiting on the mutex. The return value is zero for success.

Note that if someone has called stop_task() on this task with the wait_for_mutexes parameter set, and if the call to this function is the one that releases the tasks' last mutex, then this function won't "return" - the task_stopper() will run on this task instead.

uint8_t lock_on ( mutex_t m  ) 

Lock on a mutex.

The return value is zero for success.

Since the task may be suspended while waiting for another task to release the mutex, this function may only be called by tasks with a non-zero priority.


YAVRTOS and YAVRTOS documentation Copyright © 2007-2008 Chris O'Byrne. Email - chris <at> obyrne <dot> com