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.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:42
Provides a mutual exclusion lock primitive where a thread trying to acquire the lock waits in a loop ...
Definition spin_lock.h:36
- Header
#include <xtd/threading/spin_lock>
- Namespace
- xtd::threading
- Library
- xtd.core
- Examples
- The following example shows how to use a xtd::threading::spin_lock:
|
void | enter (bool &lock_taken) |
| 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.
|
|
void | exit () |
| Releases the lock.
|
|
void | exit (bool use_memory_barrier) |
| Releases the lock.
|
|
void | try_enter (bool &lock_taken) |
| 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.
|
|
void | try_enter (int32 milliseconds_timeout, bool &lock_taken) |
| 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.
|
|
void | try_enter (const time_span &timeout, bool &lock_taken) |
| 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.
|
|
|
| object ()=default |
| Create a new instance of the ultimate base class object.
|
|
virtual bool | equals (const object &obj) const noexcept |
| Determines whether the specified object is equal to the current object.
|
|
virtual size_t | get_hash_code () const noexcept |
| Serves as a hash function for a particular type.
|
|
virtual type_object | get_type () const noexcept |
| Gets the type of the current instance.
|
|
template<typename object_t > |
xtd::uptr< object_t > | memberwise_clone () const |
| Creates a shallow copy of the current object.
|
|
virtual xtd::string | to_string () const noexcept |
| Returns a xtd::string that represents the current object.
|
|
template<typename object_a_t , typename object_b_t > |
static bool | equals (const object_a_t &object_a, const object_b_t &object_b) noexcept |
| Determines whether the specified object instances are considered equal.
|
|
template<typename object_a_t , typename object_b_t > |
static bool | reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept |
| Determines whether the specified object instances are the same instance.
|
|
◆ spin_lock() [1/2]
xtd::threading::spin_lock::spin_lock |
( |
| ) |
|
◆ spin_lock() [2/2]
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.
- Parameters
-
enable_thread_owner_tracking | Whether to capture and use thread IDs for debugging purposes. |
◆ is_held()
bool xtd::threading::spin_lock::is_held |
( |
| ) |
const |
|
noexcept |
Gets whether the lock is currently held by any thread.
- Returns
- true if the lock is currently held by any thread; otherwise false.
◆ is_held_by_current_thread()
bool xtd::threading::spin_lock::is_held_by_current_thread |
( |
| ) |
const |
|
noexcept |
Gets whether the lock is held by the current thread.
- Returns
- true if the lock is held by the current thread; otherwise false.
◆ is_thread_owner_tracking_enabled()
bool xtd::threading::spin_lock::is_thread_owner_tracking_enabled |
( |
| ) |
const |
|
noexcept |
Gets whether thread ownership tracking is enabled for this instance.
- Returns
- true if thread ownership tracking is enabled for this instance; otherwise false.
◆ enter()
void xtd::threading::spin_lock::enter |
( |
bool & |
lock_taken | ) |
|
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.
- Parameters
-
lock_taken | True if the lock is acquired; otherwise, false. |
- Exceptions
-
◆ exit() [1/2]
void xtd::threading::spin_lock::exit |
( |
| ) |
|
Releases the lock.
- Exceptions
-
◆ exit() [2/2]
void xtd::threading::spin_lock::exit |
( |
bool |
use_memory_barrier | ) |
|
Releases the lock.
- Parameters
-
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. |
- Exceptions
-
◆ try_enter() [1/3]
void xtd::threading::spin_lock::try_enter |
( |
bool & |
lock_taken | ) |
|
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.
- Parameters
-
lock_taken | True if the lock is acquired; otherwise, false. |
- Exceptions
-
◆ try_enter() [2/3]
void xtd::threading::spin_lock::try_enter |
( |
int32 |
milliseconds_timeout, |
|
|
bool & |
lock_taken |
|
) |
| |
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.
- Parameters
-
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. |
- Exceptions
-
◆ try_enter() [3/3]
void xtd::threading::spin_lock::try_enter |
( |
const time_span & |
timeout, |
|
|
bool & |
lock_taken |
|
) |
| |
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.
- Parameters
-
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. |
- Exceptions
-
The documentation for this class was generated from the following file: