JH-Toolkit v1.4.1
An engineering-oriented C++20 toolkit with duck-typed concepts, static design, async coroutines, and semantic containers — header-only, RTTI-free, and concurrency-friendly.
Loading...
Searching...
No Matches
jh::sync::const_lock< Mutex > Class Template Referencefinal

Scope-based immutability barrier for mutex_like types. More...

#include <jh/synchronous/const_lock.h>

Public Member Functions

 const_lock (Mutex &m) noexcept
 Constructs the guard and acquires the lock.
 const_lock (const const_lock &)=delete
const_lockoperator= (const const_lock &)=delete
 const_lock (const const_lock &&)=delete
const_lockoperator= (const const_lock &&)=delete
 ~const_lock () noexcept
 Destroys the guard and releases the lock.

Detailed Description

template<jh::concepts::mutex_like Mutex>
class jh::sync::const_lock< Mutex >

Scope-based immutability barrier for mutex_like types.

A lightweight RAII guard that acquires either a shared or exclusive lock on construction and releases it on destruction.

  • If Mutex satisfies shared_lockable, lock_shared() / unlock_shared() are used.
  • Otherwise, lock() / unlock() are used.
  • If Mutex is jh::typed::null_mutex_t, all operations are no-op.

Intended for const or read-only critical sections where immutability must be preserved across threads.

Note
This guard is conceptually a read-protection mechanism. Performing any write or mutable operation within a const_lock protected scope constitutes undefined behavior (UB). Even if the underlying mutex is exclusive-only (e.g. std::mutex), the logical semantics remain read-only protection.
Template Parameters
MutexAny type satisfying jh::concepts::mutex_like.

Constructor & Destructor Documentation

◆ const_lock()

template<jh::concepts::mutex_like Mutex>
jh::sync::const_lock< Mutex >::const_lock ( Mutex & m)
inlineexplicitnoexcept

Constructs the guard and acquires the lock.

Parameters
mReference to a mutex-like object.

The documentation for this class was generated from the following file: