|
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.
|
Cross-process shared/exclusive timed mutex with optional upgrade support. More...
#include <jh/synchronous/ipc/shared_process_mutex.h>
Public Member Functions | |
| shared_process_mutex (const shared_process_mutex &)=delete | |
| shared_process_mutex & | operator= (const shared_process_mutex &)=delete |
| void | lock () |
| Acquire exclusive access (blocking). | |
| bool | try_lock () |
| Try to acquire exclusive access immediately. | |
| template<typename Rep, typename Period> | |
| bool | try_lock_for (const std::chrono::duration< Rep, Period > &d) |
| Attempt to acquire exclusive access for a limited duration. | |
| template<typename Clock, typename Duration> | |
| bool | try_lock_until (const std::chrono::time_point< Clock, Duration > &tp) |
| Attempt to acquire exclusive access until a specific time point. | |
| void | unlock () |
| Release exclusive access. | |
| void | lock_shared () |
| Acquire shared access. | |
| bool | try_lock_shared () |
| Attempt to acquire shared access immediately. | |
| template<typename Rep, typename Period> | |
| bool | try_lock_shared_for (const std::chrono::duration< Rep, Period > &d) |
| Attempt to acquire shared access for a limited duration. | |
| template<typename Clock, typename Duration> | |
| bool | try_lock_shared_until (const std::chrono::time_point< Clock, Duration > &tp) |
| Attempt to acquire shared access until a time point. | |
| void | unlock_shared () |
| Release shared access. | |
| void | upgrade_lock () |
| Upgrade from shared to exclusive mode (system-wide). | |
| void | upgrade_lock ()=delete |
| Disabled for non-privileged variants. | |
Static Public Member Functions | |
| static shared_process_mutex & | instance () |
| Access the process-wide singleton instance of this mutex. | |
| static void | unlink () |
| Remove all associated process primitives. | |
| static void | unlink ()=delete |
| Disabled for non-privileged variants. | |
Cross-process shared/exclusive timed mutex with optional upgrade support.
jh::sync::ipc::shared_process_mutex is a process-visible synchronization primitive providing shared, exclusive, and (optionally) upgradeable locking semantics, similar to std::shared_timed_mutex but implemented from process-level IPC primitives.
process_mutex<S + ".exc"> — exclusive access control. process_cond_var<S + ".cond"> — wake writers or upgraders when readers exit. process_counter<S + ".cnt"> — global reader count. process_mutex<S + ".pri"> — preemption lock for upgrade continuity. std::shared_timed_mutex interfaces (lock, try_lock*, lock_shared, try_lock_shared*). upgrade_lock() and unlink(). lock() or lock_shared() in the same execution context are idempotent. thread_local flags; release operations are similarly idempotent within the same participant. .pri to preempt writers and preserve transactional consistency. try_lock() to ensure a single active upgrader. std::shared_timed_mutex, but is implemented from process-wide IPC primitives. notify_one() is used intentionally: only writers wait on the condition variable, and at most one writer should proceed when readers complete. std::shared_lock, std::unique_lock, std::lock_guard). HighPriv == false): shared/exclusive locks only. HighPriv == true): adds upgrade support and unlink(). .exc, .cond, .cnt, and .pri.
|
inlinestatic |
Access the process-wide singleton instance of this mutex.
|
inline |
Acquire exclusive access (blocking).
Sequence:
.exc to block new readers. readers_ == 0. .pri to ensure no upgrader interferes. The participant then has full exclusive access across all processes.
|
inline |
Acquire shared access.
Locks .exc briefly to safely increment readers_, ensuring no writer is entering concurrently.
|
inline |
Try to acquire exclusive access immediately.
true if successful, false otherwise.
|
inlinestatic |
Remove all associated process primitives.
Removes the following objects from the OS namespace:
process_mutex<S + ".exc"> process_cond_var<S + ".cond"> process_counter<S + ".cnt">
|
inline |
Release exclusive access.
Steps:
.pri. .cond to wake blocked writers or upgraders. .exc.
|
inline |
Release shared access.
Decrements readers_; if this was the last reader (old == 1), signals .cond to wake one waiting writer or upgrader.
|
inline |
Upgrade from shared to exclusive mode (system-wide).
Steps:
.exc (blocks new readers). .exc is held by another writer, acquires .pri to preempt that writer and maintain upgrade continuity. .pri cannot be acquired, another upgrader is active — treated as fatal violation. This operation preserves global upgrade atomicity and ensures consistency across processes.