xtd 0.2.0
Loading...
Searching...
No Matches
spin_lock.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "../object.hpp"
6#include "../time_span.hpp"
7
9namespace xtd {
11 namespace threading {
36 class spin_lock : public object {
37 struct data;
38
39 public:
41
48 spin_lock(bool enable_thread_owner_tracking);
50
52 spin_lock(spin_lock&&) = default;
53 spin_lock(const spin_lock&) = default;
54 auto operator =(const spin_lock&) -> spin_lock& = default;
55 auto operator =(spin_lock&&) -> spin_lock& = default;
57
59
63 [[nodiscard]] auto is_held() const noexcept -> bool;
64
68 [[nodiscard]] auto is_held_by_current_thread() const noexcept -> bool;
69
72 [[nodiscard]] auto is_thread_owner_tracking_enabled() const noexcept -> bool;
74
76
82 auto enter(bool& lock_taken) -> void;
83
88 auto exit() -> void;
94 auto exit(bool use_memory_barrier) -> void;
95
100 auto try_enter(bool& lock_taken) -> void;
106 auto try_enter(int32 milliseconds_timeout, bool& lock_taken) -> void;
112 auto try_enter(const time_span& timeout, bool& lock_taken) -> void;
114
115 private:
116 mutable xtd::sptr<data> data_;
117 };
118 }
119}
object()=default
Create a new instance of the ultimate base class object.
auto enter(bool &lock_taken) -> void
Acquires the lock in a reliable manner, such that even if an exception occurs within the method call,...
auto exit() -> void
Releases the 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...
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.
spin_lock()
Initializes a new instance of the xtd::threading::spin_lock structure.
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 m...
auto is_thread_owner_tracking_enabled() const noexcept -> bool
Gets whether thread ownership tracking is enabled for this instance.
Contains a constant used to specify an infinite amount of time. This class cannot be inherited.
Definition timeout.hpp:33
Represents a time interval.
Definition time_span.hpp:29
xtd::shared_ptr_object< type_t > sptr
The xtd::sptr object is a shared pointer.
Definition sptr.hpp:25
std::int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
The xtd::threading namespace provides classes and interfaces that enable multithreaded programming....
Definition abandoned_mutex_exception.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
constexpr const_pointer data() const noexcept
Gets direct access to the underlying contiguous storage.
Definition read_only_span.hpp:201
Contains xtd::object class.
Contains xtd::time_span class.