IC Eurobot 2012 Program published from Shuto's account

Dependents:   Eurobot2012_Primary

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Mutex.h Source File

Mutex.h

00001 /* Copyright (c) 2012 mbed.org */
00002 #ifndef MUTEX_H
00003 #define MUTEX_H 
00004 
00005 #include <stdint.h>
00006 #include "cmsis_os.h"
00007 
00008 namespace rtos {
00009 
00010 /*! The Mutex class is used to synchronise the execution of threads.
00011  This is for example used to protect access to a shared resource.
00012 */
00013 class Mutex  {
00014 public:
00015     /*! Create and Initialize a Mutex object */
00016     Mutex ();
00017     
00018     /*! Wait until a Mutex becomes available.
00019       \param   millisec  timeout value or 0 in case of no time-out. (default: osWaitForever)
00020       \return  status code that indicates the execution status of the function.
00021      */ 
00022     osStatus lock (uint32_t millisec=osWaitForever);
00023     
00024     /*! Try to lock the mutex, and return immediately
00025       \return  true if the mutex was acquired, false otherwise.
00026      */
00027     bool trylock ();
00028     
00029     /*! Unlock the mutex that has previously been locked by the same thread
00030       \return  status code that indicates the execution status of the function. 
00031      */
00032     osStatus unlock ();
00033 
00034 private:
00035     osMutexId _osMutexId;
00036     osMutexDef_t _osMutexDef;
00037 #ifdef CMSIS_OS_RTX
00038     int32_t _mutex_data[3];
00039 #endif
00040 };
00041 
00042 }
00043 #endif