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::ipc::process_shm_obj< S, T, HighPriv > Class Template Referencefinal

Cross-process shared-memory container for a single POD-like object. More...

#include <jh/synchronous/ipc/process_shm_obj.h>

Public Member Functions

 process_shm_obj (const process_shm_obj &)=delete
process_shm_obj & operator= (const process_shm_obj &)=delete
T * ptr () noexcept
 Obtain non-const pointer to the shared object.
const T * ptr () const noexcept
 Obtain const pointer to the shared object.
T & ref () noexcept
 Obtain non-const reference to the shared object.
const T & ref () const noexcept
 Obtain const reference to the shared object.
T * operator-> () noexcept
 Operator-> convenience accessor.
const T * operator-> () const noexcept
 Const Operator-> convenience accessor.
T & operator* () noexcept
 Operator* convenience accessor.
const T & operator* () const noexcept
 Const Operator* convenience accessor.
lock_t & lock () noexcept
 Accessor for the inter-process mutex protecting this shared object.

Static Public Member Functions

static process_shm_obj & instance ()
 Singleton accessor.
static void flush_acquire () noexcept
 Acquire fence ensuring visibility of preceding writes by other processes.
static void flush_release () noexcept
 Release fence ensuring visibility of local writes to other processes.
static void flush_seq () noexcept
 Sequential-consistency fence for full memory ordering.
static void unlink ()
 Remove the shared-memory region and associated mutexes (POSIX only).
static void unlink ()=delete
 Disabled if HighPriv == false. Non-privileged variants cannot call unlink().

Detailed Description

template<jh::meta::TStr S, jh::pod::cv_free_pod_like T, bool HighPriv = false>
requires (limits::valid_object_name<S, limits::max_name_length - 4>())
class jh::sync::ipc::process_shm_obj< S, T, HighPriv >

Cross-process shared-memory container for a single POD-like object.

Provides a memory-mapped instance of T visible to all processes sharing the same name S. Synchronization and initialization are managed internally via named process-level mutexes.

Template Parameters
SShared-memory name literal (letters, digits, dot, dash, underscore).
TPOD-like type satisfying cv_free_pod_like.
HighPrivEnables privileged operations (e.g. unlink()).

Member Function Documentation

◆ flush_acquire()

template<jh::meta::TStr S, jh::pod::cv_free_pod_like T, bool HighPriv = false>
void jh::sync::ipc::process_shm_obj< S, T, HighPriv >::flush_acquire ( )
inlinestaticnoexcept

Acquire fence ensuring visibility of preceding writes by other processes.

Use this before reading from the shared object to guarantee memory ordering.

◆ flush_release()

template<jh::meta::TStr S, jh::pod::cv_free_pod_like T, bool HighPriv = false>
void jh::sync::ipc::process_shm_obj< S, T, HighPriv >::flush_release ( )
inlinestaticnoexcept

Release fence ensuring visibility of local writes to other processes.

Call this before releasing the lock after modifying the shared object.

◆ flush_seq()

template<jh::meta::TStr S, jh::pod::cv_free_pod_like T, bool HighPriv = false>
void jh::sync::ipc::process_shm_obj< S, T, HighPriv >::flush_seq ( )
inlinestaticnoexcept

Sequential-consistency fence for full memory ordering.

Equivalent to std::atomic_thread_fence(std::memory_order_seq_cst).

◆ lock()

template<jh::meta::TStr S, jh::pod::cv_free_pod_like T, bool HighPriv = false>
lock_t & jh::sync::ipc::process_shm_obj< S, T, HighPriv >::lock ( )
inlinenodiscardnoexcept

Accessor for the inter-process mutex protecting this shared object.

Returns
Reference to the internal process_mutex<S + ".loc">.

◆ operator*() [1/2]

template<jh::meta::TStr S, jh::pod::cv_free_pod_like T, bool HighPriv = false>
const T & jh::sync::ipc::process_shm_obj< S, T, HighPriv >::operator* ( ) const
inlinenodiscardnoexcept

Const Operator* convenience accessor.

Returns
Const reference to the shared object.

◆ operator*() [2/2]

template<jh::meta::TStr S, jh::pod::cv_free_pod_like T, bool HighPriv = false>
T & jh::sync::ipc::process_shm_obj< S, T, HighPriv >::operator* ( )
inlinenodiscardnoexcept

Operator* convenience accessor.

Returns
Reference to the shared object.

◆ operator->() [1/2]

template<jh::meta::TStr S, jh::pod::cv_free_pod_like T, bool HighPriv = false>
const T * jh::sync::ipc::process_shm_obj< S, T, HighPriv >::operator-> ( ) const
inlinenodiscardnoexcept

Const Operator-> convenience accessor.

Returns
Const pointer to the shared object.

◆ operator->() [2/2]

template<jh::meta::TStr S, jh::pod::cv_free_pod_like T, bool HighPriv = false>
T * jh::sync::ipc::process_shm_obj< S, T, HighPriv >::operator-> ( )
inlinenodiscardnoexcept

Operator-> convenience accessor.

Returns
Pointer to the shared object.

◆ ptr() [1/2]

template<jh::meta::TStr S, jh::pod::cv_free_pod_like T, bool HighPriv = false>
const T * jh::sync::ipc::process_shm_obj< S, T, HighPriv >::ptr ( ) const
inlinenodiscardnoexcept

Obtain const pointer to the shared object.

Returns
Const pointer to the mapped shared instance.

◆ ptr() [2/2]

template<jh::meta::TStr S, jh::pod::cv_free_pod_like T, bool HighPriv = false>
T * jh::sync::ipc::process_shm_obj< S, T, HighPriv >::ptr ( )
inlinenodiscardnoexcept

Obtain non-const pointer to the shared object.

Returns
Pointer to the mapped shared instance of T.

◆ ref() [1/2]

template<jh::meta::TStr S, jh::pod::cv_free_pod_like T, bool HighPriv = false>
const T & jh::sync::ipc::process_shm_obj< S, T, HighPriv >::ref ( ) const
inlinenodiscardnoexcept

Obtain const reference to the shared object.

Returns
Const reference to the shared instance.

◆ ref() [2/2]

template<jh::meta::TStr S, jh::pod::cv_free_pod_like T, bool HighPriv = false>
T & jh::sync::ipc::process_shm_obj< S, T, HighPriv >::ref ( )
inlinenodiscardnoexcept

Obtain non-const reference to the shared object.

Returns
Reference to the shared instance.

◆ unlink()

template<jh::meta::TStr S, jh::pod::cv_free_pod_like T, bool HighPriv = false>
void jh::sync::ipc::process_shm_obj< S, T, HighPriv >::unlink ( )
inlinestatic

Remove the shared-memory region and associated mutexes (POSIX only).

Semantics

  • Calls shm_unlink() for the mapped object name.
  • Then removes both process_mutex and process_mutex<S + ".loc">.
  • Ignores ENOENT if the object does not exist.
  • Throws std::runtime_error on other errors.

Idempotency

The operation is idempotent and safe to call multiple times. Once all processes unmap, the region is destroyed by the OS.

Windows

Windows provides no explicit unlink; shared handles are released automatically when all processes close them.


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