You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

52 lines
1.3 KiB

#include "mutex.hpp"
#define TAG "zmutex"
using namespace iflytop;
/*******************************************************************************
* zmutex *
*******************************************************************************/
zmutex::zmutex() {}
zmutex::~zmutex() {
#ifdef PC_IFLYTOP_ENABLE_OS
vSemaphoreDelete(recursiveMutex);
#endif
}
void zmutex::init() {
#ifdef PC_IFLYTOP_ENABLE_OS
recursiveMutex = xSemaphoreCreateRecursiveMutex();
#endif
}
bool zmutex::isInit() {
#ifdef PC_IFLYTOP_ENABLE_OS
return recursiveMutex != NULL;
#else
return true;
#endif
}
void zmutex::lock() {
#ifdef PC_IFLYTOP_ENABLE_OS
ZEARLY_ASSERT(recursiveMutex != NULL);
xSemaphoreTakeRecursive(recursiveMutex, portMAX_DELAY);
#else
chip_critical_enter();
#endif
}
void zmutex::unlock() {
#ifdef PC_IFLYTOP_ENABLE_OS
xSemaphoreGiveRecursive(recursiveMutex);
#else
chip_critical_exit();
#endif
}
/*******************************************************************************
* zlock_guard *
*******************************************************************************/
zlock_guard::zlock_guard(zmutex& mutex) : m_mutex(mutex) {
m_mutex.lock();
}
zlock_guard::~zlock_guard() { m_mutex.unlock(); }