xtd 1.0.0
Loading...
Searching...
No Matches
interlocked.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "../core_export.hpp"
6#include "../lock_guard.hpp"
7#include "../object.hpp"
8#include "../static.hpp"
9#include "../types.hpp"
10
12namespace xtd {
14 namespace threading {
41 public:
43
49 static auto add(int32& location, int32 value) noexcept -> int32;
54 static auto add(int64& location, int64 value) noexcept -> int64;
55
61 static auto compare_exchange(double& location, double value, double comparand) noexcept -> double;
67 static auto compare_exchange(int32& location, int32 value, int32 comparand) noexcept -> int32;
73 static auto compare_exchange(int64& location, int64 value, int64 comparand) noexcept -> int64;
79 static auto compare_exchange(bool& location, bool value, bool comparand) noexcept -> bool;
81 static auto compare_exchange(slong& location, slong value, slong comparand) noexcept -> slong;
88 static auto compare_exchange(void*& location, void* value, void* comparand) noexcept -> void*;
94 template<typename type_t>
95 requires std::is_enum_v<type_t>
96 static auto compare_exchange(type_t& location, type_t value, type_t comparand) noexcept -> type_t {
97 auto* location_ptr = reinterpret_cast<std::underlying_type<type_t>::type*>(&location);
98 return static_cast<type_t>(compare_exchange(*location_ptr, static_cast<std::underlying_type<type_t>::type>(value), static_cast<std::underlying_type<type_t>::type>(comparand)));
99 }
100
105 static auto compare_exchange(float& location, float value, float comparand) noexcept -> float;
106
113 static auto decrement(int32& location) noexcept -> int32;
117 static auto decrement(int64& location) noexcept -> int64;
118
123 template<typename type_t>
124 requires std::is_enum_v<type_t>
125 static auto exchange(type_t& location, const type_t& value) noexcept -> type_t {
126 auto* location_ptr = reinterpret_cast<std::underlying_type<type_t>::type*>(&location);
127 return static_cast<type_t>(exchange(*location_ptr, static_cast<std::underlying_type<type_t>::type>(value)));
128 }
129
133 static auto exchange(double& location, double value) noexcept -> double;
141 static auto exchange(int32& location, int32 value) noexcept -> int32;
146 static auto exchange(int64& location, int64 value) noexcept -> int64;
151 static auto exchange(bool& location, bool value) noexcept -> bool;
153 static auto exchange(slong& location, slong value) noexcept -> slong;
159 static auto exchange(void*& location, void* value) noexcept -> void*;
164 static auto exchange(float& location, float value) noexcept -> float;
165
172 static auto increment(int32& location) noexcept -> int32;
176 static auto increment(int64& location) noexcept -> int64;
177
182 static auto memory_barrier() noexcept -> void;
183
187 static auto read(int64& location) noexcept -> int64;
189 };
190 }
191}
Provides atomic operations for variables that are shared by multiple threads.
Definition interlocked.hpp:40
static auto exchange(int64 &location, int64 value) noexcept -> int64
Sets a 64-bit signed integer to a specified value and returns the original value, as an atomic operat...
static auto compare_exchange(int32 &location, int32 value, int32 comparand) noexcept -> int32
Compares two 32-bit signed integers for equality and, if they are equal, replaces one of the values.
static auto decrement(int32 &location) noexcept -> int32
Decrements a specified variable and stores the result, as an atomic operation.
static auto compare_exchange(type_t &location, type_t value, type_t comparand) noexcept -> type_t
Compares two instances of the specified reference type type_t for equality and, if they are equal,...
Definition interlocked.hpp:96
static auto add(int32 &location, int32 value) noexcept -> int32
Adds two 32-bit integers and replaces the first integer with the sum, as an atomic operation.
static auto exchange(type_t &location, const type_t &value) noexcept -> type_t
Sets an object to a specified value and returns the original value, as an atomic operation.
Definition interlocked.hpp:125
static auto compare_exchange(void *&location, void *value, void *comparand) noexcept -> void *
Compares two platform-specific handles or pointers for equality and, if they are equal,...
static auto increment(int64 &location) noexcept -> int64
Increments a specified variable and stores the result, as an atomic operation.
static auto increment(int32 &location) noexcept -> int32
Increments a specified variable and stores the result, as an atomic operation.
static auto compare_exchange(int64 &location, int64 value, int64 comparand) noexcept -> int64
Compares two 64-bit signed integers for equality and, if they are equal, replaces one of the values.
static auto read(int64 &location) noexcept -> int64
Returns a 64-bit value, loaded as an atomic operation.
static auto compare_exchange(bool &location, bool value, bool comparand) noexcept -> bool
Compares two bool for equality and, if they are equal, replaces one of the values.
static auto exchange(float &location, float value) noexcept -> float
Sets a double-precision floating point number to a specified value and returns the original value,...
static auto exchange(int32 &location, int32 value) noexcept -> int32
Sets a 32-bit signed integer to a specified value and returns the original value, as an atomic operat...
static auto exchange(void *&location, void *value) noexcept -> void *
Sets a platform-specific handles or pointers to a specified value and returns the original value,...
static auto add(int64 &location, int64 value) noexcept -> int64
Adds two 64-bit integers and replaces the first integer with the sum, as an atomic operation.
static auto compare_exchange(float &location, float value, float comparand) noexcept -> float
Compares two Single for equality and, if they are equal, replaces one of the values.
static auto memory_barrier() noexcept -> void
Synchronizes memory access as follows: The processor that executes the current thread cannot reorder ...
static auto exchange(bool &location, bool value) noexcept -> bool
Sets a bool to a specified value and returns the original value, as an atomic operation.
static auto decrement(int64 &location) noexcept -> int64
Decrements a specified variable and stores the result, as an atomic operation.
static auto compare_exchange(double &location, double value, double comparand) noexcept -> double
Compares two Double for equality and, if they are equal, replaces one of the values.
static auto exchange(double &location, double value) noexcept -> double
Sets a double-precision floating point number to a specified value and returns the original value,...
Contains core_export_ keyword.
auto() -> void
Signals a breakpoint to an attached debugger.
Definition debugger.hpp:75
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.hpp:38
#define core_export_
Define shared library export.
Definition core_export.hpp:13
std::int64_t int64
Represents a 64-bit signed integer.
Definition int64.hpp:23
__slong__ slong
Represents a 32-bit or 64-bit signed integer.
Definition slong.hpp:27
std::int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:25
Contains lock_guard_ keyword.
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
Contains xtd::object class.
Contains xtd::static_object class.
Contains xtd fundamental types.