StormByte C++ Library 0.0.9999
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
1#pragma once
2
3#include <StormByte/visibility.h>
4
5#include <mutex>
6#include <optional>
7#include <thread>
8
16namespace StormByte {
17 class STORMBYTE_PUBLIC ThreadLock final {
18 public:
33 constexpr ThreadLock() noexcept = default;
34
35 ThreadLock(const ThreadLock&) = delete;
36 // std::mutex is nor movable in Windows.
37 ThreadLock(ThreadLock&&) = delete;
38
45 ~ThreadLock() noexcept;
46
47 ThreadLock& operator=(const ThreadLock&) = delete;
48 ThreadLock& operator=(ThreadLock&&) = delete;
49
57 void Lock() noexcept;
58
66 void Unlock() noexcept;
67
68 private:
69 std::optional<std::thread::id> m_owner_thread_id;
70 std::mutex m_main_mutex, m_thread_owner_mutex;
71 };
72}
Definition thread_lock.hxx:17
~ThreadLock() noexcept
Destroy the ThreadLock and release any held resources.
Main namespace for the StormByte library.