Provides a mutual exclusion lock primitive where a thread trying to acquire the lock waits in a loop repeatedly checking until the lock becomes available.
Public Constructors | |
| spin_lock () | |
| Initializes a new instance of the xtd::threading::spin_lock structure. | |
| spin_lock (bool enable_thread_owner_tracking) | |
| Initializes a new instance of the xtd::threading::spin_lock structure with the option to track thread IDs to improve debugging. | |
Public Properties | |
| auto | is_held () const noexcept -> bool |
| Gets whether the lock is currently held by any thread. | |
| auto | is_held_by_current_thread () const noexcept -> bool |
| Gets whether the lock is held by the current thread. | |
| auto | is_thread_owner_tracking_enabled () const noexcept -> bool |
| Gets whether thread ownership tracking is enabled for this instance. | |
Public Methods | |
| auto | enter (bool &lock_taken) -> void |
| Acquires the lock in a reliable manner, such that even if an exception occurs within the method call, lock_taken can be examined reliably to determine whether the lock was acquired. | |
| auto | exit () -> void |
| Releases the lock. | |
| auto | exit (bool use_memory_barrier) -> void |
| Releases the lock. | |
| auto | try_enter (bool &lock_taken) -> void |
| Attempts to acquire the lock in a reliable manner, such that even if an exception occurs within the method call, lock_taken can be examined reliably to determine whether the lock was acquired. | |
| auto | try_enter (int32 milliseconds_timeout, bool &lock_taken) -> void |
| Attempts to acquire the lock in a reliable manner, such that even if an exception occurs within the method call, lock_taken can be examined reliably to determine whether the lock was acquired. | |
| auto | try_enter (const time_span &timeout, bool &lock_taken) -> void |
| Attempts to acquire the lock in a reliable manner, such that even if an exception occurs within the method call, lock_taken can be examined reliably to determine whether the lock was acquired. | |
Additional Inherited Members | |
| object ()=default | |
| Create a new instance of the ultimate base class object. | |
| virtual auto | equals (const object &obj) const noexcept -> bool |
| Determines whether the specified object is equal to the current object. | |
| virtual auto | get_hash_code () const noexcept -> xtd::usize |
| Serves as a hash function for a particular type. | |
| virtual auto | get_type () const noexcept -> type_object |
| Gets the type of the current instance. | |
| template<typename object_t> | |
| auto | memberwise_clone () const -> xtd::unique_ptr_object< object_t > |
| Creates a shallow copy of the current object. | |
| virtual auto | to_string () const -> xtd::string |
| Returns a xtd::string that represents the current object. | |
| template<typename object_a_t, typename object_b_t> | |
| static auto | equals (const object_a_t &object_a, const object_b_t &object_b) noexcept -> bool |
| Determines whether the specified object instances are considered equal. | |
| template<typename object_a_t, typename object_b_t> | |
| static auto | reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept -> bool |
| Determines whether the specified object instances are the same instance. | |
| xtd::threading::spin_lock::spin_lock | ( | ) |
Initializes a new instance of the xtd::threading::spin_lock structure.
| xtd::threading::spin_lock::spin_lock | ( | bool | enable_thread_owner_tracking | ) |
Initializes a new instance of the xtd::threading::spin_lock structure with the option to track thread IDs to improve debugging.
| enable_thread_owner_tracking | Whether to capture and use thread IDs for debugging purposes. |
|
nodiscardnoexcept |
Gets whether the lock is currently held by any thread.
|
nodiscardnoexcept |
Gets whether the lock is held by the current thread.
|
nodiscardnoexcept |
Gets whether thread ownership tracking is enabled for this instance.
| auto xtd::threading::spin_lock::enter | ( | bool & | lock_taken | ) | -> void |
Acquires the lock in a reliable manner, such that even if an exception occurs within the method call, lock_taken can be examined reliably to determine whether the lock was acquired.
| lock_taken | True if the lock is acquired; otherwise, false. |
| xtd::threading::lock_recursion_exception | Thread ownership tracking is enabled, and the current thread has already acquired this lock. |
| auto xtd::threading::spin_lock::exit | ( | ) | -> void |
Releases the lock.
| xtd::threading::synchronization_lock_exception | Thread ownership tracking is enabled, and the current thread is not the owner of this lock. |
| auto xtd::threading::spin_lock::exit | ( | bool | use_memory_barrier | ) | -> void |
Releases the lock.
| use_memory_barrier | A bool value that indicates whether a memory fence should be issued in order to immediately publish the exit operation to other threads. |
| xtd::threading::synchronization_lock_exception | Thread ownership tracking is enabled, and the current thread is not the owner of this lock. |
| auto xtd::threading::spin_lock::try_enter | ( | bool & | lock_taken | ) | -> void |
Attempts to acquire the lock in a reliable manner, such that even if an exception occurs within the method call, lock_taken can be examined reliably to determine whether the lock was acquired.
| lock_taken | True if the lock is acquired; otherwise, false. |
| xtd::threading::lock_recursion_exception | Thread ownership tracking is enabled, and the current thread has already acquired this lock. |
| auto xtd::threading::spin_lock::try_enter | ( | int32 | milliseconds_timeout, |
| bool & | lock_taken ) -> void |
Attempts to acquire the lock in a reliable manner, such that even if an exception occurs within the method call, lock_taken can be examined reliably to determine whether the lock was acquired.
| milliseconds_timeout | The number of milliseconds to wait, or xtd::threading::timeout::infinite (-1) to wait indefinitely. |
| lock_taken | True if the lock is acquired; otherwise, false. |
| xtd::threading::lock_recursion_exception | Thread ownership tracking is enabled, and the current thread has already acquired this lock. |
| auto xtd::threading::spin_lock::try_enter | ( | const time_span & | timeout, |
| bool & | lock_taken ) -> void |
Attempts to acquire the lock in a reliable manner, such that even if an exception occurs within the method call, lock_taken can be examined reliably to determine whether the lock was acquired.
| timeout | A xtd::time_span that represents the number of milliseconds to wait, or a xtd::time_span that represents -1 milliseconds to wait indefinitely. |
| lock_taken | True if the lock is acquired; otherwise, false. |
| xtd::threading::lock_recursion_exception | Thread ownership tracking is enabled, and the current thread has already acquired this lock. |