diff options
Diffstat (limited to 'mpm/lib/spi/spi_lock.h')
-rw-r--r-- | mpm/lib/spi/spi_lock.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/mpm/lib/spi/spi_lock.h b/mpm/lib/spi/spi_lock.h new file mode 100644 index 000000000..55ddb0baf --- /dev/null +++ b/mpm/lib/spi/spi_lock.h @@ -0,0 +1,25 @@ +#pragma once + +#include <boost/noncopyable.hpp> +#include <memory> +#include <mutex> + +class spi_lock : public boost::noncopyable +{ +public: + using sptr = std::shared_ptr<spi_lock>; + static sptr make(uint8_t spidev_index); + + spi_lock(uint8_t spidev_index); + + uint8_t get_spidev() const; + +private: + const uint8_t spidev_index; + + // BasicLockable implementation for lock_guard + mutable std::mutex spi_mutex; + friend class std::lock_guard<spi_lock>; + void lock(); + void unlock(); +};
\ No newline at end of file |