StormByte C++ Library 1.2.0
StormByte is a comprehensive, cross-platform C++ library aimed at easing system programming, configuration management, logging, and database handling tasks. This library provides a unified API that abstracts away the complexities and inconsistencies of different platforms (Windows, Linux).
Loading...
Searching...
No Matches
thread_lock.hxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte.
5 *
6 * StormByte is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License version 3
8 * or later, as published by the Free Software Foundation.
9 *
10 * StormByte is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with StormByte. If not, see
17 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
18 */
19
20#pragma once
21
23
24#include <mutex>
25#include <optional>
26#include <thread>
27
32namespace StormByte {
42 public:
46 ThreadLock() noexcept = default;
47
51 ThreadLock(const ThreadLock&) = delete;
52
57
62 ~ThreadLock() noexcept;
63
67 ThreadLock& operator=(const ThreadLock&) = delete;
68
72 ThreadLock& operator=(ThreadLock&&) = delete;
73
80 void Lock() noexcept;
81
87 void Unlock() noexcept;
88
89 private:
90 std::optional<std::thread::id> m_owner_thread_id;
91 std::mutex m_main_mutex;
92 std::mutex m_thread_owner_mutex;
93 };
94}
Mutex with owner-thread reentry.
Definition thread_lock.hxx:41
ThreadLock() noexcept=default
Unlocked lock, no owner.
Root namespace of the StormByte suite.
STL namespace.
#define STORMBYTE_PUBLIC
Definition visibility.h:28