2023-05-03 14:01:32 +03:00
|
|
|
|
/*
|
|
|
|
|
|
* mutex.cpp
|
|
|
|
|
|
*
|
2024-02-21 10:41:56 +03:00
|
|
|
|
* Created on: 26 сент. 2022 г.
|
2023-05-03 14:01:32 +03:00
|
|
|
|
* Author: sychev
|
|
|
|
|
|
*/
|
2023-06-26 18:22:30 +03:00
|
|
|
|
#include "free_rtos/mutex/mutex.hpp"
|
2023-05-03 14:01:32 +03:00
|
|
|
|
#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();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|