From Jason Turner

[atomics.types.int]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmphdydjuxh/{from.md → to.md} +73 -50
tmp/tmphdydjuxh/{from.md → to.md} RENAMED
@@ -1,68 +1,73 @@
1
  ### Specializations for integers <a id="atomics.types.int">[[atomics.types.int]]</a>
2
 
3
- There are specializations of the `atomic` template for the integral
4
- types `char`, `signed char`, `unsigned char`, `short`, `unsigned short`,
5
- `int`, `unsigned int`, `long`, `unsigned long`, `long long`,
6
- `unsigned long long`, `char16_t`, `char32_t`, `wchar_t`, and any other
7
- types needed by the typedefs in the header `<cstdint>`. For each such
8
- integral type `integral`, the specialization `atomic<integral>` provides
9
- additional atomic operations appropriate to integral types.
 
10
 
11
- [*Note 1*: For the specialization `atomic<bool>`, see
12
  [[atomics.types.generic]]. — *end note*]
13
 
14
  ``` cpp
15
  namespace std {
16
  template<> struct atomic<integral> {
17
  using value_type = integral;
18
  using difference_type = value_type;
 
19
  static constexpr bool is_always_lock_free = implementation-defined // whether a given atomic type's operations are always lock free;
20
  bool is_lock_free() const volatile noexcept;
21
  bool is_lock_free() const noexcept;
22
- void store(integral, memory_order = memory_order_seq_cst) volatile noexcept;
23
- void store(integral, memory_order = memory_order_seq_cst) noexcept;
24
- integral load(memory_order = memory_order_seq_cst) const volatile noexcept;
25
- integral load(memory_order = memory_order_seq_cst) const noexcept;
26
- operator integral() const volatile noexcept;
27
- operator integral() const noexcept;
28
- integral exchange(integral, memory_order = memory_order_seq_cst) volatile noexcept;
29
- integral exchange(integral, memory_order = memory_order_seq_cst) noexcept;
30
- bool compare_exchange_weak(integral&, integral,
31
- memory_order, memory_order) volatile noexcept;
32
- bool compare_exchange_weak(integral&, integral,
33
- memory_order, memory_order) noexcept;
34
- bool compare_exchange_strong(integral&, integral,
35
- memory_order, memory_order) volatile noexcept;
36
- bool compare_exchange_strong(integral&, integral,
37
- memory_order, memory_order) noexcept;
38
- bool compare_exchange_weak(integral&, integral,
39
- memory_order = memory_order_seq_cst) volatile noexcept;
40
- bool compare_exchange_weak(integral&, integral,
41
- memory_order = memory_order_seq_cst) noexcept;
42
- bool compare_exchange_strong(integral&, integral,
43
- memory_order = memory_order_seq_cst) volatile noexcept;
44
- bool compare_exchange_strong(integral&, integral,
45
- memory_order = memory_order_seq_cst) noexcept;
46
- integral fetch_add(integral, memory_order = memory_order_seq_cst) volatile noexcept;
47
- integral fetch_add(integral, memory_order = memory_order_seq_cst) noexcept;
48
- integral fetch_sub(integral, memory_order = memory_order_seq_cst) volatile noexcept;
49
- integral fetch_sub(integral, memory_order = memory_order_seq_cst) noexcept;
50
- integral fetch_and(integral, memory_order = memory_order_seq_cst) volatile noexcept;
51
- integral fetch_and(integral, memory_order = memory_order_seq_cst) noexcept;
52
- integral fetch_or(integral, memory_order = memory_order_seq_cst) volatile noexcept;
53
- integral fetch_or(integral, memory_order = memory_order_seq_cst) noexcept;
54
- integral fetch_xor(integral, memory_order = memory_order_seq_cst) volatile noexcept;
55
- integral fetch_xor(integral, memory_order = memory_order_seq_cst) noexcept;
56
 
57
- atomic() noexcept = default;
58
  constexpr atomic(integral) noexcept;
59
  atomic(const atomic&) = delete;
60
  atomic& operator=(const atomic&) = delete;
61
  atomic& operator=(const atomic&) volatile = delete;
 
 
 
62
  integral operator=(integral) volatile noexcept;
63
  integral operator=(integral) noexcept;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
  integral operator++(int) volatile noexcept;
66
  integral operator++(int) noexcept;
67
  integral operator--(int) volatile noexcept;
68
  integral operator--(int) noexcept;
@@ -78,51 +83,69 @@ namespace std {
78
  integral operator&=(integral) noexcept;
79
  integral operator|=(integral) volatile noexcept;
80
  integral operator|=(integral) noexcept;
81
  integral operator^=(integral) volatile noexcept;
82
  integral operator^=(integral) noexcept;
 
 
 
 
 
 
 
83
  };
84
  }
85
  ```
86
 
87
  The atomic integral specializations are standard-layout structs. They
88
- each have a trivial default constructor and a trivial destructor.
89
 
90
  Descriptions are provided below only for members that differ from the
91
  primary template.
92
 
93
  The following operations perform arithmetic computations. The key,
94
  operator, and computation correspondence is:
95
 
96
- **Table: Atomic arithmetic computations** <a id="tab:atomic.arithmetic.computations">[tab:atomic.arithmetic.computations]</a>
97
 
98
  | | | | | | |
99
  | ----- | --- | -------------------- | ----- | --- | -------------------- |
100
  | `add` | `+` | addition | `sub` | `-` | subtraction |
101
  | `or` | `|` | bitwise inclusive or | `xor` | `^` | bitwise exclusive or |
102
  | `and` | `&` | bitwise and | | | |
103
 
104
  ``` cpp
105
- T fetch_key(T operand, memory_order order = memory_order_seq_cst) volatile noexcept;
106
- T fetch_key(T operand, memory_order order = memory_order_seq_cst) noexcept;
107
  ```
108
 
 
 
 
109
  *Effects:* Atomically replaces the value pointed to by `this` with the
110
  result of the computation applied to the value pointed to by `this` and
111
  the given `operand`. Memory is affected according to the value of
112
  `order`. These operations are atomic read-modify-write
113
- operations ([[intro.multithread]]).
114
 
115
  *Returns:* Atomically, the value pointed to by `this` immediately before
116
  the effects.
117
 
118
- *Remarks:* For signed integer types, arithmetic is defined to use two’s
119
- complement representation. There are no undefined results.
 
 
 
 
 
120
 
121
  ``` cpp
122
  T operator op=(T operand) volatile noexcept;
123
  T operator op=(T operand) noexcept;
124
  ```
125
 
 
 
 
126
  *Effects:* Equivalent to:
127
  `return fetch_`*`key`*`(operand) `*`op`*` operand;`
128
 
 
1
  ### Specializations for integers <a id="atomics.types.int">[[atomics.types.int]]</a>
2
 
3
+ There are specializations of the `atomic` class template for the
4
+ integral types `char`, `signed char`, `unsigned char`, `short`,
5
+ `unsigned short`, `int`, `unsigned int`, `long`, `unsigned long`,
6
+ `long long`, `unsigned long long`, `char8_t`, `char16_t`, `char32_t`,
7
+ `wchar_t`, and any other types needed by the typedefs in the header
8
+ `<cstdint>`. For each such type `integral`, the specialization
9
+ `atomic<integral>` provides additional atomic operations appropriate to
10
+ integral types.
11
 
12
+ [*Note 1*: The specialization `atomic<bool>` uses the primary template
13
  [[atomics.types.generic]]. — *end note*]
14
 
15
  ``` cpp
16
  namespace std {
17
  template<> struct atomic<integral> {
18
  using value_type = integral;
19
  using difference_type = value_type;
20
+
21
  static constexpr bool is_always_lock_free = implementation-defined // whether a given atomic type's operations are always lock free;
22
  bool is_lock_free() const volatile noexcept;
23
  bool is_lock_free() const noexcept;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
+ constexpr atomic() noexcept;
26
  constexpr atomic(integral) noexcept;
27
  atomic(const atomic&) = delete;
28
  atomic& operator=(const atomic&) = delete;
29
  atomic& operator=(const atomic&) volatile = delete;
30
+
31
+ void store(integral, memory_order = memory_order::seq_cst) volatile noexcept;
32
+ void store(integral, memory_order = memory_order::seq_cst) noexcept;
33
  integral operator=(integral) volatile noexcept;
34
  integral operator=(integral) noexcept;
35
+ integral load(memory_order = memory_order::seq_cst) const volatile noexcept;
36
+ integral load(memory_order = memory_order::seq_cst) const noexcept;
37
+ operator integral() const volatile noexcept;
38
+ operator integral() const noexcept;
39
+
40
+ integral exchange(integral, memory_order = memory_order::seq_cst) volatile noexcept;
41
+ integral exchange(integral, memory_order = memory_order::seq_cst) noexcept;
42
+ bool compare_exchange_weak(integral&, integral,
43
+ memory_order, memory_order) volatile noexcept;
44
+ bool compare_exchange_weak(integral&, integral,
45
+ memory_order, memory_order) noexcept;
46
+ bool compare_exchange_strong(integral&, integral,
47
+ memory_order, memory_order) volatile noexcept;
48
+ bool compare_exchange_strong(integral&, integral,
49
+ memory_order, memory_order) noexcept;
50
+ bool compare_exchange_weak(integral&, integral,
51
+ memory_order = memory_order::seq_cst) volatile noexcept;
52
+ bool compare_exchange_weak(integral&, integral,
53
+ memory_order = memory_order::seq_cst) noexcept;
54
+ bool compare_exchange_strong(integral&, integral,
55
+ memory_order = memory_order::seq_cst) volatile noexcept;
56
+ bool compare_exchange_strong(integral&, integral,
57
+ memory_order = memory_order::seq_cst) noexcept;
58
+
59
+ integral fetch_add(integral, memory_order = memory_order::seq_cst) volatile noexcept;
60
+ integral fetch_add(integral, memory_order = memory_order::seq_cst) noexcept;
61
+ integral fetch_sub(integral, memory_order = memory_order::seq_cst) volatile noexcept;
62
+ integral fetch_sub(integral, memory_order = memory_order::seq_cst) noexcept;
63
+ integral fetch_and(integral, memory_order = memory_order::seq_cst) volatile noexcept;
64
+ integral fetch_and(integral, memory_order = memory_order::seq_cst) noexcept;
65
+ integral fetch_or(integral, memory_order = memory_order::seq_cst) volatile noexcept;
66
+ integral fetch_or(integral, memory_order = memory_order::seq_cst) noexcept;
67
+ integral fetch_xor(integral, memory_order = memory_order::seq_cst) volatile noexcept;
68
+ integral fetch_xor(integral, memory_order = memory_order::seq_cst) noexcept;
69
 
70
  integral operator++(int) volatile noexcept;
71
  integral operator++(int) noexcept;
72
  integral operator--(int) volatile noexcept;
73
  integral operator--(int) noexcept;
 
83
  integral operator&=(integral) noexcept;
84
  integral operator|=(integral) volatile noexcept;
85
  integral operator|=(integral) noexcept;
86
  integral operator^=(integral) volatile noexcept;
87
  integral operator^=(integral) noexcept;
88
+
89
+ void wait(integral, memory_order = memory_order::seq_cst) const volatile noexcept;
90
+ void wait(integral, memory_order = memory_order::seq_cst) const noexcept;
91
+ void notify_one() volatile noexcept;
92
+ void notify_one() noexcept;
93
+ void notify_all() volatile noexcept;
94
+ void notify_all() noexcept;
95
  };
96
  }
97
  ```
98
 
99
  The atomic integral specializations are standard-layout structs. They
100
+ each have a trivial destructor.
101
 
102
  Descriptions are provided below only for members that differ from the
103
  primary template.
104
 
105
  The following operations perform arithmetic computations. The key,
106
  operator, and computation correspondence is:
107
 
108
+ **Table: Atomic arithmetic computations** <a id="atomic.types.int.comp">[atomic.types.int.comp]</a>
109
 
110
  | | | | | | |
111
  | ----- | --- | -------------------- | ----- | --- | -------------------- |
112
  | `add` | `+` | addition | `sub` | `-` | subtraction |
113
  | `or` | `|` | bitwise inclusive or | `xor` | `^` | bitwise exclusive or |
114
  | `and` | `&` | bitwise and | | | |
115
 
116
  ``` cpp
117
+ T fetch_key(T operand, memory_order order = memory_order::seq_cst) volatile noexcept;
118
+ T fetch_key(T operand, memory_order order = memory_order::seq_cst) noexcept;
119
  ```
120
 
121
+ *Constraints:* For the `volatile` overload of this function,
122
+ `is_always_lock_free` is `true`.
123
+
124
  *Effects:* Atomically replaces the value pointed to by `this` with the
125
  result of the computation applied to the value pointed to by `this` and
126
  the given `operand`. Memory is affected according to the value of
127
  `order`. These operations are atomic read-modify-write
128
+ operations [[intro.multithread]].
129
 
130
  *Returns:* Atomically, the value pointed to by `this` immediately before
131
  the effects.
132
 
133
+ *Remarks:* For signed integer types, the result is as if the object
134
+ value and parameters were converted to their corresponding unsigned
135
+ types, the computation performed on those types, and the result
136
+ converted back to the signed type.
137
+
138
+ [*Note 1*: There are no undefined results arising from the
139
+ computation. — *end note*]
140
 
141
  ``` cpp
142
  T operator op=(T operand) volatile noexcept;
143
  T operator op=(T operand) noexcept;
144
  ```
145
 
146
+ *Constraints:* For the `volatile` overload of this function,
147
+ `is_always_lock_free` is `true`.
148
+
149
  *Effects:* Equivalent to:
150
  `return fetch_`*`key`*`(operand) `*`op`*` operand;`
151