Skip to content

Commit de1fceb

Browse files
committed
Add noexcept to fb_atomic, move static_assert out of constructor
1 parent 992bccd commit de1fceb

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

src/common/classes/fb_atomic.h

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,35 +37,34 @@ class AtomicCounter
3737
public:
3838
typedef IPTR counter_type;
3939

40-
explicit AtomicCounter(counter_type value = 0)
40+
explicit AtomicCounter(counter_type value = 0) noexcept
4141
: counter(value)
4242
{
43-
static_assert(sizeof(counter_type) == sizeof(counter), "Internal and external counter sizes need to match");
4443
}
4544

4645
~AtomicCounter()
4746
{
4847
}
4948

50-
counter_type value() const { return counter.load(std::memory_order_acquire); }
49+
counter_type value() const noexcept { return counter.load(std::memory_order_acquire); }
5150

52-
counter_type exchangeAdd(counter_type value)
51+
counter_type exchangeAdd(counter_type value) noexcept
5352
{
5453
return counter.fetch_add(value);
5554
}
5655

57-
void setValue(counter_type val)
56+
void setValue(counter_type val) noexcept
5857
{
5958
counter.store(val, std::memory_order_release);
6059
}
6160

62-
bool compareExchange(counter_type oldVal, counter_type newVal)
61+
bool compareExchange(counter_type oldVal, counter_type newVal) noexcept
6362
{
6463
return counter.compare_exchange_strong(oldVal, newVal);
6564
}
6665

6766
// returns old value
68-
counter_type exchangeBitAnd(counter_type val)
67+
counter_type exchangeBitAnd(counter_type val) noexcept
6968
{
7069
while (true)
7170
{
@@ -76,7 +75,7 @@ class AtomicCounter
7675
}
7776

7877
// returns old value
79-
counter_type exchangeBitOr(counter_type val)
78+
counter_type exchangeBitOr(counter_type val) noexcept
8079
{
8180
while (true)
8281
{
@@ -87,7 +86,7 @@ class AtomicCounter
8786
}
8887

8988
// returns old value
90-
counter_type exchangeGreater(counter_type val)
89+
counter_type exchangeGreater(counter_type val) noexcept
9190
{
9291
while (true)
9392
{
@@ -102,7 +101,7 @@ class AtomicCounter
102101
}
103102

104103
// returns old value
105-
counter_type exchangeLower(counter_type val)
104+
counter_type exchangeLower(counter_type val) noexcept
106105
{
107106
while (true)
108107
{
@@ -116,50 +115,52 @@ class AtomicCounter
116115
}
117116
}
118117

119-
void operator &=(counter_type val)
118+
void operator &=(counter_type val) noexcept
120119
{
121120
counter &= val;
122121
}
123122

124-
void operator |=(counter_type val)
123+
void operator |=(counter_type val) noexcept
125124
{
126125
counter |= val;
127126
}
128127

129128
// returns new value !
130-
counter_type operator ++()
129+
counter_type operator ++() noexcept
131130
{
132131
return counter++ + 1;
133132
}
134133

135134
// returns new value !
136-
counter_type operator --()
135+
counter_type operator --() noexcept
137136
{
138137
return counter-- - 1;
139138
}
140139

141-
inline operator counter_type () const
140+
inline operator counter_type () const noexcept
142141
{
143142
return value();
144143
}
145144

146-
inline void operator =(counter_type val)
145+
inline void operator =(counter_type val) noexcept
147146
{
148147
setValue(val);
149148
}
150149

151-
inline counter_type operator +=(counter_type val)
150+
inline counter_type operator +=(counter_type val) noexcept
152151
{
153152
return exchangeAdd(val) + val;
154153
}
155154

156-
inline counter_type operator -=(counter_type val)
155+
inline counter_type operator -=(counter_type val) noexcept
157156
{
158157
return exchangeAdd(-val) - val;
159158
}
160159

161160
private:
162161
std::atomic<counter_type> counter;
162+
163+
static_assert(sizeof(counter_type) == sizeof(counter), "Internal and external counter sizes need to match");
163164
};
164165

165166
} // namespace Firebird

0 commit comments

Comments
 (0)