SatNOGS-COMMS  4.1.0
A COMMS subsystem for CubeSats
Loading...
Searching...
No Matches
scoped_lock.hpp
Go to the documentation of this file.
1/*
2 * SatNOGS-COMMS MCU software
3 *
4 * Copyright (C) 2022-2023, Libre Space Foundation <http://libre.space>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * SPDX-License-Identifier: GNU General Public License v3.0 or later
20 */
21
22#pragma once
23
24#include <zephyr/kernel.h>
25
26namespace satnogs::comms
27{
28
34{
35public:
41 scoped_lock(struct k_mutex *mutex) : m_mtx(mutex)
42 {
43 k_mutex_lock(m_mtx, K_FOREVER);
44 }
45
51 scoped_lock(struct k_mutex &mutex) : m_mtx(&mutex)
52 {
53 k_mutex_lock(m_mtx, K_FOREVER);
54 }
55
60 ~scoped_lock() { k_mutex_unlock(m_mtx); }
61
62private:
63 struct k_mutex *m_mtx;
64};
65
66} // namespace satnogs::comms
~scoped_lock()
Upon destruction, the mutex is released.
scoped_lock(struct k_mutex &mutex)
Creates a scoped lock.
scoped_lock(struct k_mutex *mutex)
Creates a scoped lock.