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.
 
 

35 lines
1.0 KiB

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