xtd 0.2.0
Loading...
Searching...
No Matches
interlocked.h
Go to the documentation of this file.
1
4#pragma once
5#include "../core_export.h"
6#include "../lock.h"
7#include "../object.h"
8#include "../static.h"
9#include "../types.h"
10
12namespace xtd {
14 namespace threading {
39 public:
41
47 static int32 add(int32& location, int32 value) noexcept;
52 static int64 add(int64& location, int64 value) noexcept;
53
59 static double compare_exchange(double& location, double value, double comparand) noexcept;
65 static int32 compare_exchange(int32& location, int32 value, int32 comparand) noexcept;
71 static int64 compare_exchange(int64& location, int64 value, int64 comparand) noexcept;
73 static slong compare_exchange(slong& location, slong value, slong comparand) noexcept;
80 static void* compare_exchange(void*& location, void* value, void* comparand) noexcept;
86 template<typename type_t>
87 static type_t compare_exchange(object& location, const object& value, const object& comparand) noexcept {
88 type_t retValue = location;
89 lock_(location) {
90 if (location.equals(comparand)) location = value;
91 }
92 return retValue;
93 }
99 template<typename type_t>
100 static type_t compare_exchange(type_t& location, type_t value, type_t comparand) noexcept {
101 type_t retValue = location;
102 lock_(location) {
103 if (location == comparand) location = value;
104 }
105 return retValue;
106 }
112 static float compare_exchange(float& location, float value, float comparand) noexcept;
113
120 static int32 decrement(int32& location) noexcept;
124 static int64 decrement(int64& location) noexcept;
125
130 template<typename type_t>
131 static type_t exchange(type_t& location, type_t value) {
132 type_t original = location;
133 lock_(location)
134 location = value;
135 return original;
136 }
141 static double exchange(double& location, double value) noexcept;
149 static int32 exchange(int32& location, int32 value) noexcept;
154 static int64 exchange(int64& location, int64 value) noexcept;
156 static slong exchange(slong& location, slong value) noexcept;
162 static void* exchange(void*& location, void* value) noexcept;
167 template<typename type_t>
168 static type_t exchange(object& location, const object& value) noexcept {
169 type_t original = location;
170 lock_(location)
171 location = value;
172 return original;
173 }
178 static float exchange(float& location, float value) noexcept;
179
186 static int32 increment(int32& location) noexcept;
190 static int64 increment(int64& location) noexcept;
191
196 static void memory_barrier() noexcept;
197
201 static int64 read(int64& location) noexcept;
203 };
204 }
205}
Provides atomic operations for variables that are shared by multiple threads.
Definition interlocked.h:38
static double exchange(double &location, double value) noexcept
Sets a double-precision floating point number to a specified value and returns the original value,...
static int32 add(int32 &location, int32 value) noexcept
Adds two 32-bit integers and replaces the first integer with the sum, as an atomic operation.
static int64 exchange(int64 &location, int64 value) noexcept
Sets a 64-bit signed integer to a specified value and returns the original value, as an atomic operat...
static double compare_exchange(double &location, double value, double comparand) noexcept
Compares two Double for equality and, if they are equal, replaces one of the values.
static type_t exchange(object &location, const object &value) noexcept
Sets an object to a specified value and returns the original value, as an atomic operation.
Definition interlocked.h:168
static void memory_barrier() noexcept
Synchronizes memory access as follows: The processor that executes the current thread cannot reorder ...
static int32 increment(int32 &location) noexcept
Increments a specified variable and stores the result, as an atomic operation.
static int64 add(int64 &location, int64 value) noexcept
Adds two 64-bit integers and replaces the first integer with the sum, as an atomic operation.
static type_t compare_exchange(type_t &location, type_t value, type_t comparand) noexcept
Compares two instances of the specified reference type type_t for equality and, if they are equal,...
Definition interlocked.h:100
static void * exchange(void *&location, void *value) noexcept
Sets a platform-specific handles or pointers to a specified value and returns the original value,...
static int32 decrement(int32 &location) noexcept
Decrements a specified variable and stores the result, as an atomic operation.
static int64 compare_exchange(int64 &location, int64 value, int64 comparand) noexcept
Compares two 64-bit signed integers for equality and, if they are equal, replaces one of the values.
static type_t compare_exchange(object &location, const object &value, const object &comparand) noexcept
Compares two objects for equality and, if they are equal, replaces one of them.
Definition interlocked.h:87
static int32 compare_exchange(int32 &location, int32 value, int32 comparand) noexcept
Compares two 32-bit signed integers for equality and, if they are equal, replaces one of the values.
static float compare_exchange(float &location, float value, float comparand) noexcept
Compares two Single for equality and, if they are equal, replaces one of the values.
static void * compare_exchange(void *&location, void *value, void *comparand) noexcept
Compares two platform-specific handles or pointers for equality and, if they are equal,...
static float exchange(float &location, float value) noexcept
Sets a double-precision floating point number to a specified value and returns the original value,...
static int64 increment(int64 &location) noexcept
Increments a specified variable and stores the result, as an atomic operation.
static int64 decrement(int64 &location) noexcept
Decrements a specified variable and stores the result, as an atomic operation.
static int32 exchange(int32 &location, int32 value) noexcept
Sets a 32-bit signed integer to a specified value and returns the original value, as an atomic operat...
static type_t exchange(type_t &location, type_t value)
Sets a variable of the specified type type_t to a specified value and returns the original value,...
Definition interlocked.h:131
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.h:37
#define core_export_
Define shared library export.
Definition core_export.h:13
#define lock_(object)
The lock_ keyword marks a statement block as a critical section by obtaining the mutual-exclusion loc...
Definition lock.h:85
int_least64_t int64
Represents a 64-bit signed integer.
Definition types.h:142
int_least32_t int32
Represents a 32-bit signed integer.
Definition types.h:131
__slong__ slong
Represents a 32-bit or 64-bit signed integer.
Definition types.h:208
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10