sitara_depot/components/free_rtos/mutex/mutex.hpp

58 lines
1.0 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* mutex.hpp
*
* Created on: 26 сент. 2022 г.
* Author: sychev
*/
#ifndef SRC_MUTEX_MUTEX_HPP_
#define SRC_MUTEX_MUTEX_HPP_
#include <kernel/freertos/FreeRTOS-Kernel/include/FreeRTOS.h>
#include <kernel/freertos/FreeRTOS-Kernel/include/semphr.h>
namespace free_rtos {
/**
* @brief С++ обертка на мьютексом из ti rtos
*
*/
class Mutex {
public:
Mutex();
/**
* wait - время ожидания в тиках, по умолчанию
* portMAX_DELAY - ожидание бесконечно, 0 - ожидание отсутствует
* Вызвращает pdTRUE если удалось получить семафор
*/
BaseType_t lock(TickType_t wait = portMAX_DELAY);
void unlock(void);
~Mutex();
private:
SemaphoreHandle_t handle_;
};
/**
* @brief Реализация паттерна LockGuard
*
*/
class LockGuard {
public:
LockGuard(Mutex& mutex);
~LockGuard();
private:
Mutex& mutex_;
};
}
#endif /* SRC_MUTEX_MUTEX_HPP_ */