mutex++

Dependents:   header_main_publish

Fork of mbed-rtos by mbed official

Committer:
emilmont
Date:
Fri Nov 23 09:57:31 2012 +0000
Revision:
6:350b53afb889
Child:
8:88a1a9c26ae3
Merge RTOS C++ API and RTX under the same library; Update RTX to version 4.60; Add proper Thread destructor;

Who changed what in which revision?

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