Official mbed Real Time Operating System based on the RTX implementation of the CMSIS-RTOS API open standard.
Dependents: LoRaWAN-lmic-app LoRaWAN-lmic-app LoRaWAN-test-10secs testes ... more
Diff: rtos/Mutex.cpp
- Revision:
- 6:350b53afb889
- Child:
- 8:88a1a9c26ae3
diff -r 9654a71f5a90 -r 350b53afb889 rtos/Mutex.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rtos/Mutex.cpp Fri Nov 23 09:57:31 2012 +0000 @@ -0,0 +1,35 @@ +#include "Mutex.h" + +#include <string.h> +#include "error.h" + +namespace rtos { + +Mutex::Mutex() { +#ifdef CMSIS_OS_RTX + memset(_mutex_data, 0, sizeof(_mutex_data)); + _osMutexDef.mutex = _mutex_data; +#endif + _osMutexId = osMutexCreate(&_osMutexDef); + if (_osMutexId == NULL) { + error("Error initializing the mutex object\n"); + } +} + +osStatus Mutex::lock(uint32_t millisec) { + return osMutexWait(_osMutexId, millisec); +} + +bool Mutex::trylock() { + return (osMutexWait(_osMutexId, 0) == osOK); +} + +osStatus Mutex::unlock() { + return osMutexRelease(_osMutexId); +} + +Mutex::~Mutex() { + osMutexDelete(_osMutexId); +} + +}