36 lines
644 B
C++
36 lines
644 B
C++
/*
|
||
* mutex.cpp
|
||
*
|
||
* Created on: 26 сент. 2022 г.
|
||
* Author: sychev
|
||
*/
|
||
#include "free_rtos/mutex/mutex.hpp"
|
||
#include <kernel/dpl/DebugP.h>
|
||
|
||
free_rtos::Mutex::Mutex() {
|
||
handle_ = xSemaphoreCreateMutex();
|
||
DebugP_assert(nullptr != handle_);
|
||
}
|
||
|
||
BaseType_t free_rtos::Mutex::lock(TickType_t wait) {
|
||
return xSemaphoreTake( handle_, wait );
|
||
}
|
||
|
||
void free_rtos::Mutex::unlock(void) {
|
||
xSemaphoreGive(handle_);
|
||
}
|
||
|
||
free_rtos::Mutex::~Mutex() {
|
||
vSemaphoreDelete(handle_);
|
||
}
|
||
|
||
free_rtos::LockGuard::LockGuard(Mutex& mutex) : mutex_{mutex} {
|
||
mutex_.lock();
|
||
}
|
||
|
||
free_rtos::LockGuard::~LockGuard() {
|
||
mutex_.unlock();
|
||
}
|
||
|
||
|