|
PACS System 0.1.0
PACS DICOM system library
|
Manages locks on DICOM studies for concurrent access control. More...
#include <study_lock_manager.h>

Classes | |
| struct | lock_entry |
Public Types | |
| using | lock_event_callback |
| Callback type for lock events. | |
Public Member Functions | |
| study_lock_manager () | |
| Construct lock manager with default configuration. | |
| study_lock_manager (const study_lock_manager_config &config) | |
| Construct lock manager with custom configuration. | |
| ~study_lock_manager () | |
| Destructor - releases all locks. | |
| study_lock_manager (const study_lock_manager &)=delete | |
| Non-copyable. | |
| study_lock_manager & | operator= (const study_lock_manager &)=delete |
| study_lock_manager (study_lock_manager &&) noexcept | |
| Movable. | |
| study_lock_manager & | operator= (study_lock_manager &&) noexcept |
| auto | lock (const std::string &study_uid, const std::string &reason, const std::string &holder="", std::chrono::seconds timeout=std::chrono::seconds{0}) -> kcenon::common::Result< lock_token > |
| Acquire an exclusive lock on a study. | |
| auto | lock (const std::string &study_uid, lock_type type, const std::string &reason, const std::string &holder="", std::chrono::seconds timeout=std::chrono::seconds{0}) -> kcenon::common::Result< lock_token > |
| Acquire a lock of specific type on a study. | |
| auto | try_lock (const std::string &study_uid, lock_type type, const std::string &reason, const std::string &holder="", std::chrono::seconds timeout=std::chrono::seconds{0}) -> kcenon::common::Result< lock_token > |
| Try to acquire a lock without blocking. | |
| auto | unlock (const lock_token &token) -> kcenon::common::Result< std::monostate > |
| Release a lock using its token. | |
| auto | unlock (const std::string &study_uid, const std::string &holder) -> kcenon::common::Result< std::monostate > |
| Release a lock by study UID and holder. | |
| auto | force_unlock (const std::string &study_uid, const std::string &admin_reason="") -> kcenon::common::Result< std::monostate > |
| Force release a lock (admin operation) | |
| auto | unlock_all_by_holder (const std::string &holder) -> std::size_t |
| Release all locks held by a specific holder. | |
| auto | is_locked (const std::string &study_uid) const -> bool |
| Check if a study is locked. | |
| auto | is_locked (const std::string &study_uid, lock_type type) const -> bool |
| Check if a study has a specific lock type. | |
| auto | get_lock_info (const std::string &study_uid) const -> std::optional< lock_info > |
| Get lock information for a study. | |
| auto | get_lock_info_by_token (const std::string &token_id) const -> std::optional< lock_info > |
| Get lock information by token ID. | |
| auto | validate_token (const lock_token &token) const -> bool |
| Validate a lock token. | |
| auto | refresh_lock (const lock_token &token, std::chrono::seconds extension=std::chrono::seconds{0}) -> kcenon::common::Result< lock_token > |
| Refresh a lock (extend its timeout) | |
| auto | get_all_locks () const -> std::vector< lock_info > |
| Get all currently held locks. | |
| auto | get_locks_by_holder (const std::string &holder) const -> std::vector< lock_info > |
| Get all locks held by a specific holder. | |
| auto | get_locks_by_type (lock_type type) const -> std::vector< lock_info > |
| Get all locks of a specific type. | |
| auto | get_expired_locks () const -> std::vector< lock_info > |
| Get all expired locks. | |
| auto | cleanup_expired_locks () -> std::size_t |
| Clean up expired locks. | |
| auto | get_stats () const -> lock_manager_stats |
| Get lock manager statistics. | |
| void | reset_stats () |
| Reset statistics counters. | |
| auto | get_config () const -> const study_lock_manager_config & |
| Get the current configuration. | |
| void | set_config (const study_lock_manager_config &config) |
| Update configuration. | |
| void | set_on_lock_acquired (lock_event_callback callback) |
| Set callback for lock acquisition events. | |
| void | set_on_lock_released (lock_event_callback callback) |
| Set callback for lock release events. | |
| void | set_on_lock_expired (lock_event_callback callback) |
| Set callback for lock expiration events. | |
Private Member Functions | |
| auto | generate_token_id () const -> std::string |
| Generate a unique token ID. | |
| auto | resolve_holder (const std::string &holder) const -> std::string |
| Get holder identifier (uses thread ID if empty) | |
| auto | calculate_expiry (std::chrono::seconds timeout) const -> std::optional< std::chrono::system_clock::time_point > |
| Calculate expiration time. | |
| auto | can_acquire_lock (const std::string &study_uid, lock_type type) const -> bool |
| Check if a lock can be acquired. | |
| void | record_acquisition (lock_type type) |
| Update statistics on lock acquisition. | |
| void | record_release (lock_type type, std::chrono::milliseconds duration) |
| Update statistics on lock release. | |
Private Attributes | |
| study_lock_manager_config | config_ |
| Configuration. | |
| std::map< std::string, lock_entry > | locks_ |
| Lock entries (study_uid -> lock_entry) | |
| std::map< std::string, std::string > | token_to_study_ |
| Token to study UID mapping for fast lookup. | |
| std::shared_mutex | mutex_ |
| Mutex for thread-safe access. | |
| lock_manager_stats | stats_ |
| Statistics. | |
| std::mutex | stats_mutex_ |
| Mutex for statistics. | |
| std::atomic< uint64_t > | next_token_id_ {1} |
| Next token ID counter. | |
| lock_event_callback | on_lock_acquired_ |
| Event callbacks. | |
| lock_event_callback | on_lock_released_ |
| lock_event_callback | on_lock_expired_ |
Manages locks on DICOM studies for concurrent access control.
The study_lock_manager provides thread-safe locking mechanisms for DICOM studies to prevent concurrent modifications and ensure data integrity.
When multiple lock requests compete:
Definition at line 337 of file study_lock_manager.h.
Callback type for lock events.
Definition at line 610 of file study_lock_manager.h.
| kcenon::pacs::workflow::study_lock_manager::study_lock_manager | ( | ) |
Construct lock manager with default configuration.
Definition at line 26 of file study_lock_manager.cpp.
|
explicit |
Construct lock manager with custom configuration.
| config | Lock manager configuration |
Definition at line 29 of file study_lock_manager.cpp.
| kcenon::pacs::workflow::study_lock_manager::~study_lock_manager | ( | ) |
Destructor - releases all locks.
Definition at line 32 of file study_lock_manager.cpp.
References lock(), locks_, mutex_, and token_to_study_.

|
delete |
Non-copyable.
|
noexcept |
Movable.
Definition at line 39 of file study_lock_manager.cpp.
|
nodiscardprivate |
Calculate expiration time.
Definition at line 813 of file study_lock_manager.cpp.
|
nodiscardprivate |
Check if a lock can be acquired.
Definition at line 823 of file study_lock_manager.cpp.
References kcenon::pacs::workflow::shared.
| auto kcenon::pacs::workflow::study_lock_manager::cleanup_expired_locks | ( | ) | -> std::size_t |
Clean up expired locks.
Definition at line 687 of file study_lock_manager.cpp.
|
nodiscard |
Force release a lock (admin operation)
| study_uid | Study UID to unlock |
| admin_reason | Reason for force unlock |
Definition at line 366 of file study_lock_manager.cpp.
References kcenon::pacs::workflow::lock_error::not_found, and kcenon::pacs::workflow::lock_error::permission_denied.
|
nodiscardprivate |
Generate a unique token ID.
Definition at line 787 of file study_lock_manager.cpp.
References next_token_id_.
|
nodiscard |
Get all currently held locks.
Definition at line 613 of file study_lock_manager.cpp.
References lock(), locks_, and mutex_.

|
nodiscard |
Get the current configuration.
Definition at line 757 of file study_lock_manager.cpp.
References config_.
|
nodiscard |
Get all expired locks.
Definition at line 669 of file study_lock_manager.cpp.
References lock(), locks_, and mutex_.

|
nodiscard |
Get lock information for a study.
| study_uid | Study UID to query |
Definition at line 506 of file study_lock_manager.cpp.
|
nodiscard |
Get lock information by token ID.
| token_id | Token ID to query |
Definition at line 522 of file study_lock_manager.cpp.
|
nodiscard |
Get all locks held by a specific holder.
| holder | Identifier of the lock holder |
Definition at line 628 of file study_lock_manager.cpp.
References kcenon::pacs::workflow::shared.
|
nodiscard |
Get all locks of a specific type.
| type | Lock type to filter by |
Definition at line 654 of file study_lock_manager.cpp.
|
nodiscard |
Get lock manager statistics.
Definition at line 722 of file study_lock_manager.cpp.
References kcenon::pacs::workflow::lock_manager_stats::active_locks, kcenon::pacs::workflow::exclusive, kcenon::pacs::workflow::lock_manager_stats::exclusive_locks, lock(), locks_, kcenon::pacs::workflow::migration, kcenon::pacs::workflow::lock_manager_stats::migration_locks, mutex_, kcenon::pacs::workflow::shared, kcenon::pacs::workflow::lock_manager_stats::shared_locks, stats_, and stats_mutex_.

|
nodiscard |
Check if a study is locked.
| study_uid | Study UID to check |
Definition at line 473 of file study_lock_manager.cpp.
|
nodiscard |
Check if a study has a specific lock type.
| study_uid | Study UID to check |
| type | Lock type to check for |
Definition at line 489 of file study_lock_manager.cpp.
|
nodiscard |
Acquire an exclusive lock on a study.
| study_uid | Study UID to lock |
| reason | Reason for acquiring the lock |
| holder | Identifier of the lock holder (default: current thread) |
| timeout | Optional timeout for the lock (0 = use default) |
Definition at line 69 of file study_lock_manager.cpp.
References kcenon::pacs::workflow::exclusive.
Referenced by get_all_locks(), get_expired_locks(), get_stats(), set_config(), and ~study_lock_manager().

|
nodiscard |
Acquire a lock of specific type on a study.
| study_uid | Study UID to lock |
| type | Type of lock to acquire |
| reason | Reason for acquiring the lock |
| holder | Identifier of the lock holder |
| timeout | Optional timeout for the lock |
Definition at line 77 of file study_lock_manager.cpp.
References kcenon::pacs::workflow::lock_info::acquired_at, kcenon::pacs::workflow::lock_token::acquired_at, kcenon::pacs::workflow::lock_error::already_locked, kcenon::pacs::workflow::lock_info::expires_at, kcenon::pacs::workflow::lock_token::expires_at, kcenon::pacs::workflow::lock_info::holder, kcenon::pacs::workflow::study_lock_manager::lock_entry::info, kcenon::pacs::workflow::lock_error::max_shared_exceeded, kcenon::pacs::workflow::lock_info::reason, kcenon::pacs::workflow::shared, kcenon::pacs::workflow::lock_info::shared_count, kcenon::pacs::workflow::study_lock_manager::lock_entry::shared_holders, kcenon::pacs::workflow::lock_info::study_uid, kcenon::pacs::workflow::lock_token::study_uid, kcenon::pacs::workflow::to_string(), kcenon::pacs::workflow::lock_info::token_id, kcenon::pacs::workflow::lock_token::token_id, kcenon::pacs::workflow::lock_info::type, and kcenon::pacs::workflow::lock_token::type.

|
delete |
|
noexcept |
Definition at line 49 of file study_lock_manager.cpp.
|
private |
Update statistics on lock acquisition.
Definition at line 844 of file study_lock_manager.cpp.
References stats_, stats_mutex_, and kcenon::pacs::workflow::lock_manager_stats::total_acquisitions.
|
private |
Update statistics on lock release.
Definition at line 850 of file study_lock_manager.cpp.
References kcenon::pacs::workflow::lock_manager_stats::avg_lock_duration, kcenon::pacs::workflow::lock_manager_stats::max_lock_duration, stats_, stats_mutex_, and kcenon::pacs::workflow::lock_manager_stats::total_releases.
|
nodiscard |
Refresh a lock (extend its timeout)
| token | Lock token to refresh |
| extension | Additional time to extend the lock |
Definition at line 564 of file study_lock_manager.cpp.
References kcenon::pacs::workflow::lock_error::expired, kcenon::pacs::workflow::lock_token::expires_at, kcenon::pacs::workflow::lock_error::invalid_token, and kcenon::pacs::workflow::lock_error::not_found.
| void kcenon::pacs::workflow::study_lock_manager::reset_stats | ( | ) |
Reset statistics counters.
Definition at line 752 of file study_lock_manager.cpp.
References stats_, and stats_mutex_.
|
nodiscardprivate |
Get holder identifier (uses thread ID if empty)
Definition at line 801 of file study_lock_manager.cpp.
| void kcenon::pacs::workflow::study_lock_manager::set_config | ( | const study_lock_manager_config & | config | ) |
Update configuration.
Note: Changes to some settings may not take effect immediately.
| config | New configuration |
Definition at line 762 of file study_lock_manager.cpp.
References config_, lock(), and mutex_.

| void kcenon::pacs::workflow::study_lock_manager::set_on_lock_acquired | ( | lock_event_callback | callback | ) |
Set callback for lock acquisition events.
| callback | Callback function |
Definition at line 771 of file study_lock_manager.cpp.
References on_lock_acquired_.
| void kcenon::pacs::workflow::study_lock_manager::set_on_lock_expired | ( | lock_event_callback | callback | ) |
Set callback for lock expiration events.
| callback | Callback function |
Definition at line 779 of file study_lock_manager.cpp.
References on_lock_expired_.
| void kcenon::pacs::workflow::study_lock_manager::set_on_lock_released | ( | lock_event_callback | callback | ) |
Set callback for lock release events.
| callback | Callback function |
Definition at line 775 of file study_lock_manager.cpp.
References on_lock_released_.
|
nodiscard |
Try to acquire a lock without blocking.
| study_uid | Study UID to lock |
| type | Type of lock to acquire |
| reason | Reason for acquiring the lock |
| holder | Identifier of the lock holder |
| timeout | Optional timeout for the lock |
Definition at line 210 of file study_lock_manager.cpp.
|
nodiscard |
Release a lock using its token.
| token | Lock token received from lock() |
Definition at line 225 of file study_lock_manager.cpp.
References kcenon::pacs::workflow::lock_error::invalid_token, kcenon::pacs::workflow::lock_error::not_found, and kcenon::pacs::workflow::shared.
|
nodiscard |
Release a lock by study UID and holder.
| study_uid | Study UID to unlock |
| holder | Identifier of the lock holder |
Definition at line 294 of file study_lock_manager.cpp.
References kcenon::pacs::workflow::lock_error::not_found, kcenon::pacs::workflow::lock_error::permission_denied, and kcenon::pacs::workflow::shared.
| auto kcenon::pacs::workflow::study_lock_manager::unlock_all_by_holder | ( | const std::string & | holder | ) | -> std::size_t |
Release all locks held by a specific holder.
| holder | Identifier of the lock holder |
Definition at line 422 of file study_lock_manager.cpp.
References kcenon::pacs::workflow::shared.
|
nodiscard |
Validate a lock token.
| token | Lock token to validate |
Definition at line 544 of file study_lock_manager.cpp.
|
private |
Configuration.
Definition at line 688 of file study_lock_manager.h.
Referenced by get_config(), and set_config().
|
private |
Lock entries (study_uid -> lock_entry)
Definition at line 691 of file study_lock_manager.h.
Referenced by get_all_locks(), get_expired_locks(), get_stats(), and ~study_lock_manager().
|
mutableprivate |
Mutex for thread-safe access.
Definition at line 697 of file study_lock_manager.h.
Referenced by get_all_locks(), get_expired_locks(), get_stats(), set_config(), and ~study_lock_manager().
|
mutableprivate |
Next token ID counter.
Definition at line 706 of file study_lock_manager.h.
Referenced by generate_token_id().
|
private |
Event callbacks.
Definition at line 709 of file study_lock_manager.h.
Referenced by set_on_lock_acquired().
|
private |
Definition at line 711 of file study_lock_manager.h.
Referenced by set_on_lock_expired().
|
private |
Definition at line 710 of file study_lock_manager.h.
Referenced by set_on_lock_released().
|
mutableprivate |
Statistics.
Definition at line 700 of file study_lock_manager.h.
Referenced by get_stats(), record_acquisition(), record_release(), and reset_stats().
|
mutableprivate |
Mutex for statistics.
Definition at line 703 of file study_lock_manager.h.
Referenced by get_stats(), record_acquisition(), record_release(), and reset_stats().
|
private |
Token to study UID mapping for fast lookup.
Definition at line 694 of file study_lock_manager.h.
Referenced by ~study_lock_manager().