Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: ch8_mbed_websocket_client
Fork of mbed-rtos by
rtos/Mutex.cpp
- Committer:
- emilmont
- Date:
- 2012-11-23
- Revision:
- 6:350b53afb889
- Child:
- 8:88a1a9c26ae3
File content as of revision 6:350b53afb889:
#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);
}
}
