xtd 0.2.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.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;
75 static auto compare_exchange(slong& location, slong value, slong comparand) noexcept -> slong;
82 static auto compare_exchange(void*& location, void* value, void* comparand) noexcept -> void*;
88 template<class type_t>
89 static auto compare_exchange(object& location, const object& value, const object& comparand) noexcept -> type_t {
90 type_t retValue = location;
91 lock_(location) {
92 if (location.equals(comparand)) location = value;
93 }
94 return retValue;
95 }
96
101 template<class type_t>
102 static auto compare_exchange(type_t& location, type_t value, type_t comparand) noexcept -> type_t {
103 type_t retValue = location;
104 lock_(location) {
105 if (location == comparand) location = value;
106 }
107 return retValue;
108 }
109
114 static auto compare_exchange(float& location, float value, float comparand) noexcept -> float;
115
122 static auto decrement(int32& location) noexcept -> int32;
126 static auto decrement(int64& location) noexcept -> int64;
127
132 template<class type_t>
133 static auto exchange(type_t& location, type_t value) -> type_t {
134 type_t original = location;
135 lock_(location)
136 location = value;
137 return original;
138 }
139
143 static auto exchange(double& location, double value) noexcept -> double;
151 static auto exchange(int32& location, int32 value) noexcept -> int32;
156 static auto exchange(int64& location, int64 value) noexcept -> int64;
158 static auto exchange(slong& location, slong value) noexcept -> slong;
164 static auto exchange(void*& location, void* value) noexcept -> void*;
169 template<class type_t>
170 static auto exchange(object& location, const object& value) noexcept -> type_t {
171 type_t original = location;
172 lock_(location)
173 location = value;
174 return original;
175 }
176
180 static auto exchange(float& location, float value) noexcept -> float;
181
188 static auto increment(int32& location) noexcept -> int32;
192 static auto increment(int64& location) noexcept -> int64;
193
198 static auto memory_barrier() noexcept -> void;
199
203 static auto read(int64& location) noexcept -> int64;
205 };
206 }
207}
Provides atomic operations for variables that are shared by multiple threads.
Definition interlocked.hpp:40
static auto exchange(int64 &location, int64 value) noexcept -> int64
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 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 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:102
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(object &location, const object &value, const object &comparand) noexcept -> type_t
Compares two objects for equality and, if they are equal, replaces one of them.
Definition interlocked.hpp:89
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 exchange(object &location, const object &value) noexcept -> type_t
Sets an object to a specified value and returns the original value, as an atomic operation.
Definition interlocked.hpp:170
static auto read(int64 &location) noexcept -> int64
Returns a 64-bit value, loaded as an atomic operation.
static auto exchange(type_t &location, type_t value) -> type_t
Sets a variable of the specified type type_t to a specified value and returns the original value,...
Definition interlocked.hpp:133
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 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.
#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
#define lock_(object)
The lock_ keyword marks a statement block as a critical section by obtaining the mutual-exclusion loc...
Definition lock.hpp:68
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:23
Contains lock_ 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.