34 #ifndef PSYSTEM_FRAMEWORK_SHARED_HANDLE_HPP
35 #define PSYSTEM_FRAMEWORK_SHARED_HANDLE_HPP
97 template <
typename T = HANDLE, T kInval
idHandle = INVALID_HANDLE_VALUE>
162 template <
typename D>
222 static constexpr T invalid_handle_value = kInvalidHandle;
242 (kInvalidHandle != hndl)
243 ? new shared_handle_data
270 template <
typename D>
274 (kInvalidHandle != hndl)
275 ? new shared_handle_data_with_delete<D>(
std::forward<D>(deleter))
316 other.m_handle = kInvalidHandle;
317 other.m_control_block =
nullptr;
344 template <
typename D>
350 ? new shared_handle_data_with_delete<D>(
351 std::move(other.get_deleter()))
376 ? new shared_handle_data
427 if (&o ==
this)
return *
this;
461 if (&o ==
this)
return *
this;
502 template <
typename D>
506 if (&o ==
this)
return *
this;
544 if (&o ==
this)
return *
this;
581 return (kInvalidHandle !=
m_handle);
650 template <
typename D>
672 if (&o ==
this)
return;
715 auto const usage_count =
717 1, std::memory_order_relaxed);
720 if (1 == usage_count)
725 auto const weak_count =
745 1, std::memory_order_relaxed);
796 template <
typename T, T kInval
idHandle>
815 template <
typename T, T kInval
idHandle>
816 struct hash<
psystem::shared_handle<T, kInvalidHandle> >
826 return std::hash<typename shared_handle_type::handle_type>()(
850 template <
typename T, T kInval
idHandle>
855 return (h1.get() == h2.get());
873 template <
typename T, T kInval
idHandle>
896 template <
typename T, T kInval
idHandle>
921 template <
typename T, T kInval
idHandle>
944 template <
typename T, T kInval
idHandle>
967 template <
typename T, T kInval
idHandle>
975 #endif // PSYSTEM_FRAMEWORK_SHARED_HANDLE_HPP
handle_type get() const noexcept
Access the handle contained in this object.
Definition: shared_handle.hpp:595
A simple functor to close handles (for use with RAII handle containers).
Definition: default_close_handle.hpp:49
shared_handle(shared_handle &&other)
Transfer ownership of a handle from another shared_handle.
Definition: shared_handle.hpp:312
shared_handle & operator=(shared_handle const &o) noexcept
Share ownership of a handle managed by a shared_handle instance.
Definition: shared_handle.hpp:425
Uniquely manage a single "handle".
Definition: unique_handle.hpp:249
psystem::internal::managed_handle_proxy< handle_type, shared_handle< handle_type, kInvalidHandle > > safe_address_container
A safe container for altering the handle by the address-of operator.
Definition: shared_handle.hpp:214
handle_type m_handle
The handle to manage within this class.
Definition: shared_handle.hpp:756
void reset(handle_type hndl=kInvalidHandle) noexcept
Assign a new handle to be managed by this instance.
Definition: shared_handle.hpp:613
shared_handle(shared_handle const &other) noexcept
Share ownership of a handle with another shared_handle.
Definition: shared_handle.hpp:292
void swap(shared_handle &o) noexcept
Exchange ownership of two shared_handle instances.
Definition: shared_handle.hpp:670
shared_handle(handle_type hndl, D &&deleter) noexcept
Construct an instance to manage a handle with a custom "deleter.".
Definition: shared_handle.hpp:271
~shared_handle() noexcept
Release ownership of the handle by destroying this instance.
Definition: shared_handle.hpp:394
deleter_type m_deleter
A user-provided handle deletion utility.
Definition: shared_handle.hpp:200
virtual void delete_handle(T hndl) noexcept
Remove resources associated with a handle.
Definition: shared_handle.hpp:136
void increment() noexcept
Increment the managed handle's reference count.
Definition: shared_handle.hpp:738
Definition: shared_handle.hpp:782
shared_handle & operator=(psystem::unique_handle< T, D, kInvalidHandle > &&o) noexcept
Move an unique_handle instance into a shared_handle.
Definition: shared_handle.hpp:503
Disable heap allocation and deallocation.
Definition: stack_allocated.hpp:42
shared_handle(psystem::unique_handle< T, D, kInvalidHandle > &&other) noexcept
Transfer ownership of a handle from an unique_handle.
Definition: shared_handle.hpp:345
shared_handle_data * m_control_block
The shared "control block" for all instances managing the handle.
Definition: shared_handle.hpp:773
shared_handle & operator=(psystem::unique_handle< T, default_close_handle< T >, kInvalidHandle > &&o) noexcept
Transfer ownership of a handle from a default unique_handle type.
Definition: shared_handle.hpp:540
Allows safe modification of a managed handle container when accessed by the handle's address...
Definition: managed_handle_proxy.hpp:51
bool unique() const noexcept
Determines if this is the only instance managing the current handle.
Definition: shared_handle.hpp:684
HMODULE handle_type
The data-type of the handle being managed.
Definition: shared_handle.hpp:208
Declare an RAII container for system API handles (psystem::unique_handle).
std::atomic< size_t > m_usage_count
The count of shared_handle instances that are managing this handle.
Definition: shared_handle.hpp:145
std::atomic< size_t > m_weak_count
The "weak" reference count (manages the control block).
Definition: shared_handle.hpp:153
void reset(handle_type hndl, D &&deleter) noexcept
Assign a new handle to be managed by this instance with a custom deleter.
Definition: shared_handle.hpp:651
D deleter_type
The facility used to clean handle resources.
Definition: shared_handle.hpp:167
A control block for a shared_handle with a user-specified deleter.
Definition: shared_handle.hpp:163
bool operator<=(psystem::shared_handle< T, kInvalidHandle > const &h1, psystem::shared_handle< T, kInvalidHandle > const &h2) noexcept
Test if the first handle is less than or equal to the second.
Definition: shared_handle.hpp:922
shared_handle & operator=(shared_handle &&o) noexcept
Transfer ownership of a handle into this insance.
Definition: shared_handle.hpp:459
Introduces a functor to wrap CloseHandle() for RAII handle containers.
static void close_handle(T hndl) noexcept
Executes a handle clean-up routine without requiring an instance.
Definition: default_close_handle.hpp:64
size_t use_count() const noexcept
The count of shared_handle instances managing this handle.
Definition: shared_handle.hpp:694
Share management of a single "handle" between multiple owners.
Definition: shared_handle.hpp:98
shared_handle_data_with_delete(deleter_type &&deleter) noexcept
Construct this instance by taking ownership of a deleter.
Definition: shared_handle.hpp:185
Contains the process examination "system" and basic frameworks.
Definition: pstack_event_handler.hpp:28
size_t operator()(shared_handle_type const &value) const
Invoke the hash functor.
Definition: shared_handle.hpp:824
bool operator>=(psystem::shared_handle< T, kInvalidHandle > const &h1, psystem::shared_handle< T, kInvalidHandle > const &h2) noexcept
Test if the first handle is greater than or equal to the second.
Definition: shared_handle.hpp:968
virtual void delete_handle(T hndl) noexcept override
Invoke the provided deleter to clean up handle resources.
Definition: shared_handle.hpp:194
safe_address_container operator&() noexcept
Allow safe alteration of the handle by routines that return data by C-style output parameters...
Definition: shared_handle.hpp:563
virtual ~shared_handle_data() noexcept
Provide a virtual destructor for polymorphic deletion.
Definition: shared_handle.hpp:119
bool operator==(psystem::shared_handle< T, kInvalidHandle > const &h1, psystem::shared_handle< T, kInvalidHandle > const &h2) noexcept
Test for equality of two handles.
Definition: shared_handle.hpp:851
shared_handle_data() noexcept
Initialize a usage count of 1 and a weak-usage count of 1.
Definition: shared_handle.hpp:113
bool operator>(psystem::shared_handle< T, kInvalidHandle > const &h1, psystem::shared_handle< T, kInvalidHandle > const &h2) noexcept
Test if the first handle is greater than the second.
Definition: shared_handle.hpp:945
shared_handle(psystem::unique_handle< T, default_close_handle< T >, kInvalidHandle > &&other) noexcept
Transfer ownership of a handle from a default unique_handle type.
Definition: shared_handle.hpp:370
Defines the psystem::stack_allocated interface.
bool operator<(psystem::shared_handle< T, kInvalidHandle > const &h1, psystem::shared_handle< T, kInvalidHandle > const &h2) noexcept
Test if the first handle is less than the second.
Definition: shared_handle.hpp:897
The basic control block for a shared_handle.
Definition: shared_handle.hpp:110
bool operator!=(psystem::shared_handle< T, kInvalidHandle > const &h1, psystem::shared_handle< T, kInvalidHandle > const &h2) noexcept
Test for inequality of two handles.
Definition: shared_handle.hpp:874
void decrement() noexcept
Decrement the managed handle's reference count.
Definition: shared_handle.hpp:711
shared_handle(handle_type hndl=kInvalidHandle) noexcept
Construct an instance to manage a handle.
Definition: shared_handle.hpp:239
shared_handle_data_with_delete(deleter_type const &deleter) noexcept
Construct this instance with a custom deleter.
Definition: shared_handle.hpp:174