Committer:
donatien
Date:
Thu May 31 15:46:30 2012 +0000
Revision:
0:e6ccf0b3d718

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 0:e6ccf0b3d718 1 /* Copyright (c) 2012 mbed.org */
donatien 0:e6ccf0b3d718 2 #ifndef MUTEX_H
donatien 0:e6ccf0b3d718 3 #define MUTEX_H
donatien 0:e6ccf0b3d718 4
donatien 0:e6ccf0b3d718 5 #include <stdint.h>
donatien 0:e6ccf0b3d718 6 #include "cmsis_os.h"
donatien 0:e6ccf0b3d718 7
donatien 0:e6ccf0b3d718 8 namespace rtos {
donatien 0:e6ccf0b3d718 9
donatien 0:e6ccf0b3d718 10 /*! The Mutex class is used to synchronise the execution of threads.
donatien 0:e6ccf0b3d718 11 This is for example used to protect access to a shared resource.
donatien 0:e6ccf0b3d718 12 */
donatien 0:e6ccf0b3d718 13 class Mutex {
donatien 0:e6ccf0b3d718 14 public:
donatien 0:e6ccf0b3d718 15 /*! Create and Initialize a Mutex object */
donatien 0:e6ccf0b3d718 16 Mutex();
donatien 0:e6ccf0b3d718 17
donatien 0:e6ccf0b3d718 18 /*! Wait until a Mutex becomes available.
donatien 0:e6ccf0b3d718 19 \param millisec timeout value or 0 in case of no time-out. (default: osWaitForever)
donatien 0:e6ccf0b3d718 20 \return status code that indicates the execution status of the function.
donatien 0:e6ccf0b3d718 21 */
donatien 0:e6ccf0b3d718 22 osStatus lock(uint32_t millisec=osWaitForever);
donatien 0:e6ccf0b3d718 23
donatien 0:e6ccf0b3d718 24 /*! Try to lock the mutex, and return immediately
donatien 0:e6ccf0b3d718 25 \return true if the mutex was acquired, false otherwise.
donatien 0:e6ccf0b3d718 26 */
donatien 0:e6ccf0b3d718 27 bool trylock();
donatien 0:e6ccf0b3d718 28
donatien 0:e6ccf0b3d718 29 /*! Unlock the mutex that has previously been locked by the same thread
donatien 0:e6ccf0b3d718 30 \return status code that indicates the execution status of the function.
donatien 0:e6ccf0b3d718 31 */
donatien 0:e6ccf0b3d718 32 osStatus unlock();
donatien 0:e6ccf0b3d718 33
donatien 0:e6ccf0b3d718 34 private:
donatien 0:e6ccf0b3d718 35 osMutexId _osMutexId;
donatien 0:e6ccf0b3d718 36 osMutexDef_t _osMutexDef;
donatien 0:e6ccf0b3d718 37 #ifdef CMSIS_OS_RTX
donatien 0:e6ccf0b3d718 38 int32_t _mutex_data[3];
donatien 0:e6ccf0b3d718 39 #endif
donatien 0:e6ccf0b3d718 40 };
donatien 0:e6ccf0b3d718 41
donatien 0:e6ccf0b3d718 42 }
donatien 0:e6ccf0b3d718 43 #endif