Ethernetwebsoc
Dependencies: C12832_lcd LM75B WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip
mbed-rtos/rtos/Mutex.cpp@0:0ed2a7c7190c, 2013-05-31 (annotated)
- Committer:
- GordonSin
- Date:
- Fri May 31 04:09:54 2013 +0000
- Revision:
- 0:0ed2a7c7190c
31/5/2013;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GordonSin | 0:0ed2a7c7190c | 1 | #include "Mutex.h" |
GordonSin | 0:0ed2a7c7190c | 2 | |
GordonSin | 0:0ed2a7c7190c | 3 | #include <string.h> |
GordonSin | 0:0ed2a7c7190c | 4 | #include "error.h" |
GordonSin | 0:0ed2a7c7190c | 5 | |
GordonSin | 0:0ed2a7c7190c | 6 | namespace rtos { |
GordonSin | 0:0ed2a7c7190c | 7 | |
GordonSin | 0:0ed2a7c7190c | 8 | Mutex::Mutex() { |
GordonSin | 0:0ed2a7c7190c | 9 | #ifdef CMSIS_OS_RTX |
GordonSin | 0:0ed2a7c7190c | 10 | memset(_mutex_data, 0, sizeof(_mutex_data)); |
GordonSin | 0:0ed2a7c7190c | 11 | _osMutexDef.mutex = _mutex_data; |
GordonSin | 0:0ed2a7c7190c | 12 | #endif |
GordonSin | 0:0ed2a7c7190c | 13 | _osMutexId = osMutexCreate(&_osMutexDef); |
GordonSin | 0:0ed2a7c7190c | 14 | if (_osMutexId == NULL) { |
GordonSin | 0:0ed2a7c7190c | 15 | error("Error initializing the mutex object\n"); |
GordonSin | 0:0ed2a7c7190c | 16 | } |
GordonSin | 0:0ed2a7c7190c | 17 | } |
GordonSin | 0:0ed2a7c7190c | 18 | |
GordonSin | 0:0ed2a7c7190c | 19 | osStatus Mutex::lock(uint32_t millisec) { |
GordonSin | 0:0ed2a7c7190c | 20 | return osMutexWait(_osMutexId, millisec); |
GordonSin | 0:0ed2a7c7190c | 21 | } |
GordonSin | 0:0ed2a7c7190c | 22 | |
GordonSin | 0:0ed2a7c7190c | 23 | bool Mutex::trylock() { |
GordonSin | 0:0ed2a7c7190c | 24 | return (osMutexWait(_osMutexId, 0) == osOK); |
GordonSin | 0:0ed2a7c7190c | 25 | } |
GordonSin | 0:0ed2a7c7190c | 26 | |
GordonSin | 0:0ed2a7c7190c | 27 | osStatus Mutex::unlock() { |
GordonSin | 0:0ed2a7c7190c | 28 | return osMutexRelease(_osMutexId); |
GordonSin | 0:0ed2a7c7190c | 29 | } |
GordonSin | 0:0ed2a7c7190c | 30 | |
GordonSin | 0:0ed2a7c7190c | 31 | Mutex::~Mutex() { |
GordonSin | 0:0ed2a7c7190c | 32 | osMutexDelete(_osMutexId); |
GordonSin | 0:0ed2a7c7190c | 33 | } |
GordonSin | 0:0ed2a7c7190c | 34 | |
GordonSin | 0:0ed2a7c7190c | 35 | } |