xtd 0.2.0
spin_lock.h
Go to the documentation of this file.
1 #pragma once
5 #include "../object.h"
6 #include "../time_span.h"
7 
9 namespace xtd {
11  namespace threading {
34  class spin_lock : public object {
35  struct data;
36 
37  public:
39 
42  spin_lock();
46  spin_lock(bool enable_thread_owner_tracking);
48 
50  spin_lock(spin_lock&&) = default;
51  spin_lock(const spin_lock&) = default;
52  spin_lock& operator =(const spin_lock& other) = default;
54 
56 
60  bool is_held() const noexcept;
61 
65  bool is_held_by_current_thread() const noexcept;
66 
69  bool is_thread_owner_tracking_enabled() const noexcept;
71 
73 
79  void enter(bool& lock_taken);
80 
85  void exit();
91  void exit(bool use_memory_barrier);
92 
97  void try_enter(bool& lock_taken);
103  void try_enter(int32 milliseconds_timeout, bool& lock_taken);
109  void try_enter(const time_span& timeout, bool& lock_taken);
111 
112  private:
113  mutable std::shared_ptr<data> data_;
114  };
115  }
116 }
void exit()
Releases the lock.
Provides a mutual exclusion lock primitive where a thread trying to acquire the lock waits in a loop ...
Definition: spin_lock.h:34
void try_enter(bool &lock_taken)
Attempts to acquire the lock in a reliable manner, such that even if an exception occurs within the m...
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
spin_lock()
Initializes a new instance of the xtd::threading::spin_lock structure.
bool is_held() const noexcept
Gets whether the lock is currently held by any thread.
The operating system is other.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:32
Represents a time interval.
Definition: time_span.h:26
int_least32_t int32
Represents a 32-bit signed integer.
Definition: types.h:129
Contains a constant used to specify an infinite amount of time. This class cannot be inherited...
Definition: timeout.h:31
void enter(bool &lock_taken)
Acquires the lock in a reliable manner, such that even if an exception occurs within the method call...
bool is_thread_owner_tracking_enabled() const noexcept
Gets whether thread ownership tracking is enabled for this instance.
bool is_held_by_current_thread() const noexcept
Gets whether the lock is held by the current thread.