Skip to content

Commit a76a840

Browse files
ivan-cukicRalphSteinhagen
authored andcommitted
Use a distinct forceinline macro not to collide with GR
Signed-off-by: Ivan Čukić <[email protected]>
1 parent fa042fd commit a76a840

File tree

7 files changed

+111
-99
lines changed

7 files changed

+111
-99
lines changed

src/core/include/opencmw.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717
#include <print>
1818
#include <refl.hpp>
1919

20+
#include <opencmw.hpp>
21+
2022
#include <Formatter.hpp>
2123
#include <units/concepts.h>
2224
#include <units/quantity.h>
2325
#include <units/quantity_io.h>
2426

25-
#define FWD(x) std::forward<decltype(x)>(x) // short-hand notation
26-
#define forceinline inline __attribute__((always_inline)) // use this for hot-spots only <-> may bloat code size, not fit into cache and consequently slow down execution
27-
#define neverinline __attribute__((noinline)) // primarily used to avoid inlining (rare) exception handling code
27+
#define FWD(x) std::forward<decltype(x)>(x) // short-hand notation
28+
#define OPENCMW_FORCEINLINE inline __attribute__((always_inline)) // use this for hot-spots only <-> may bloat code size, not fit into cache and consequently slow down execution
29+
#define neverinline __attribute__((noinline)) // primarily used to avoid inlining (rare) exception handling code
2830

2931
#define ENABLE_REFLECTION_FOR(TypeName, ...) \
3032
REFL_TYPE(TypeName __VA_OPT__(, )) \

src/disruptor/include/disruptor/ClaimStrategy.hpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef OPENCMW_CPP_CLAIMSTRATEGY_HPP
22
#define OPENCMW_CPP_CLAIMSTRATEGY_HPP
33

4+
#include <opencmw.hpp>
5+
46
#include <SpinWait.hpp>
57

68
#include <disruptor/Sequence.hpp>
@@ -32,10 +34,10 @@ class alignas(kCacheLine) SingleThreadedStrategy {
3234

3335
public:
3436
SingleThreadedStrategy(Sequence &cursor, WAIT_STRATEGY &waitStrategy)
35-
: _cursor(cursor), _waitStrategy(waitStrategy){};
37+
: _cursor(cursor), _waitStrategy(waitStrategy) {};
3638
SingleThreadedStrategy(const SingleThreadedStrategy &) = delete;
3739
SingleThreadedStrategy(const SingleThreadedStrategy &&) = delete;
38-
void operator=(const SingleThreadedStrategy &) = delete;
40+
void operator=(const SingleThreadedStrategy &) = delete;
3941

4042
bool hasAvailableCapacity(const std::vector<std::shared_ptr<Sequence>> &dependents, const int requiredCapacity, const std::int64_t /*cursorValue*/) const noexcept {
4143
if (const std::int64_t wrapPoint = (_nextValue + requiredCapacity) - static_cast<std::int64_t>(SIZE); wrapPoint > _cachedValue || _cachedValue > _nextValue) {
@@ -99,8 +101,8 @@ class alignas(kCacheLine) SingleThreadedStrategy {
99101
}
100102
}
101103

102-
[[nodiscard]] forceinline bool isAvailable(std::int64_t sequence) const noexcept { return sequence <= _cursor.value(); }
103-
[[nodiscard]] std::int64_t getHighestPublishedSequence(std::int64_t /*nextSequence*/, std::int64_t availableSequence) const noexcept { return availableSequence; }
104+
[[nodiscard]] OPENCMW_FORCEINLINE bool isAvailable(std::int64_t sequence) const noexcept { return sequence <= _cursor.value(); }
105+
[[nodiscard]] std::int64_t getHighestPublishedSequence(std::int64_t /*nextSequence*/, std::int64_t availableSequence) const noexcept { return availableSequence; }
104106
};
105107
static_assert(ClaimStrategy<SingleThreadedStrategy<1024, NoWaitStrategy>>);
106108

@@ -128,8 +130,8 @@ class MultiThreadedStrategy {
128130
}
129131
setAvailableBufferValue(0, -1);
130132
}
131-
MultiThreadedStrategy(const MultiThreadedStrategy &) = delete;
132-
MultiThreadedStrategy(const MultiThreadedStrategy &&) = delete;
133+
MultiThreadedStrategy(const MultiThreadedStrategy &) = delete;
134+
MultiThreadedStrategy(const MultiThreadedStrategy &&) = delete;
133135
void operator=(const MultiThreadedStrategy &) = delete;
134136

135137
[[nodiscard]] bool hasAvailableCapacity(const std::vector<std::shared_ptr<Sequence>> &dependents, const std::int64_t requiredCapacity, const std::int64_t cursorValue) const noexcept {
@@ -212,14 +214,14 @@ class MultiThreadedStrategy {
212214
}
213215
}
214216

215-
[[nodiscard]] forceinline bool isAvailable(std::int64_t sequence) const noexcept {
217+
[[nodiscard]] OPENCMW_FORCEINLINE bool isAvailable(std::int64_t sequence) const noexcept {
216218
const auto index = calculateIndex(sequence);
217219
const auto flag = calculateAvailabilityFlag(sequence);
218220

219221
return _availableBuffer[static_cast<std::size_t>(index)] == flag;
220222
}
221223

222-
[[nodiscard]] forceinline std::int64_t getHighestPublishedSequence(const std::int64_t lowerBound, const std::int64_t availableSequence) const noexcept {
224+
[[nodiscard]] OPENCMW_FORCEINLINE std::int64_t getHighestPublishedSequence(const std::int64_t lowerBound, const std::int64_t availableSequence) const noexcept {
223225
for (std::int64_t sequence = lowerBound; sequence <= availableSequence; sequence++) {
224226
if (!isAvailable(sequence)) {
225227
return sequence - 1;
@@ -230,10 +232,10 @@ class MultiThreadedStrategy {
230232
}
231233

232234
private:
233-
void setAvailable(std::int64_t sequence) noexcept { setAvailableBufferValue(calculateIndex(sequence), calculateAvailabilityFlag(sequence)); }
234-
forceinline void setAvailableBufferValue(std::size_t index, std::int32_t flag) noexcept { _availableBuffer[index] = flag; }
235-
[[nodiscard]] forceinline std::int32_t calculateAvailabilityFlag(const std::int64_t sequence) const noexcept { return static_cast<std::int32_t>(static_cast<std::uint64_t>(sequence) >> _indexShift); }
236-
[[nodiscard]] forceinline std::size_t calculateIndex(const std::int64_t sequence) const noexcept { return static_cast<std::size_t>(static_cast<std::int32_t>(sequence) & _indexMask); }
235+
void setAvailable(std::int64_t sequence) noexcept { setAvailableBufferValue(calculateIndex(sequence), calculateAvailabilityFlag(sequence)); }
236+
OPENCMW_FORCEINLINE void setAvailableBufferValue(std::size_t index, std::int32_t flag) noexcept { _availableBuffer[index] = flag; }
237+
[[nodiscard]] OPENCMW_FORCEINLINE std::int32_t calculateAvailabilityFlag(const std::int64_t sequence) const noexcept { return static_cast<std::int32_t>(static_cast<std::uint64_t>(sequence) >> _indexShift); }
238+
[[nodiscard]] OPENCMW_FORCEINLINE std::size_t calculateIndex(const std::int64_t sequence) const noexcept { return static_cast<std::size_t>(static_cast<std::int32_t>(sequence) & _indexMask); }
237239
};
238240
static_assert(ClaimStrategy<MultiThreadedStrategy<1024, NoWaitStrategy>>);
239241

src/disruptor/include/disruptor/RingBuffer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class RingBuffer : public EventStore<T>, public std::enable_shared_from_this<Rin
4949
[[nodiscard]] std::int64_t tryNext(std::int32_t n_slots_to_claim = 1) override { return _claimStrategy->tryNext(*_gatingSequences, n_slots_to_claim); }
5050
[[nodiscard]] std::int64_t getRemainingCapacity() const noexcept override { return _claimStrategy->getRemainingCapacity(*_gatingSequences); }
5151
void publish(std::int64_t sequence) override { _claimStrategy->publish(sequence); }
52-
[[nodiscard]] forceinline bool isAvailable(std::int64_t sequence) const noexcept override { return _claimStrategy->isAvailable(sequence); }
52+
[[nodiscard]] OPENCMW_FORCEINLINE bool isAvailable(std::int64_t sequence) const noexcept override { return _claimStrategy->isAvailable(sequence); }
5353
[[nodiscard]] std::int64_t getHighestPublishedSequence(std::int64_t nextSequence, std::int64_t availableSequence) const noexcept override { return _claimStrategy->getHighestPublishedSequence(nextSequence, availableSequence); }
5454
[[nodiscard]] std::int64_t cursor() const noexcept override { return _cursor->value(); }
5555
[[nodiscard]] bool isPublished(std::int64_t sequence) const noexcept override { return isAvailable(sequence); }

src/disruptor/include/disruptor/Sequence.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
#include <algorithm>
55
#include <atomic>
66
#include <format>
7-
#include <opencmw.hpp>
87
#include <ostream>
98
#include <span>
109

10+
#include <opencmw.hpp>
11+
1112
namespace opencmw::disruptor {
1213

1314
static constexpr const std::size_t kCacheLine = 64;
@@ -27,24 +28,24 @@ class Sequence {
2728
explicit Sequence(std::int64_t initialValue = kInitialCursorValue) noexcept
2829
: _fieldsValue(initialValue) {}
2930

30-
[[nodiscard]] forceinline std::int64_t value() const noexcept {
31+
[[nodiscard]] OPENCMW_FORCEINLINE std::int64_t value() const noexcept {
3132
return std::atomic_load_explicit(&_fieldsValue, std::memory_order_acquire);
3233
}
3334

34-
forceinline void setValue(std::int64_t value) noexcept {
35+
OPENCMW_FORCEINLINE void setValue(std::int64_t value) noexcept {
3536
std::atomic_store_explicit(&_fieldsValue, value, std::memory_order_release);
3637
}
3738

38-
[[nodiscard]] forceinline bool compareAndSet(std::int64_t expectedSequence, std::int64_t nextSequence) noexcept {
39+
[[nodiscard]] OPENCMW_FORCEINLINE bool compareAndSet(std::int64_t expectedSequence, std::int64_t nextSequence) noexcept {
3940
// atomically set the value to the given updated value if the current value == the expected value (true, otherwise folse).
4041
return std::atomic_compare_exchange_strong(&_fieldsValue, &expectedSequence, nextSequence);
4142
}
4243

43-
[[nodiscard]] forceinline std::int64_t incrementAndGet() noexcept {
44+
[[nodiscard]] OPENCMW_FORCEINLINE std::int64_t incrementAndGet() noexcept {
4445
return std::atomic_fetch_add(&_fieldsValue, 1L) + 1L;
4546
}
4647

47-
[[nodiscard]] forceinline std::int64_t addAndGet(std::int64_t value) noexcept {
48+
[[nodiscard]] OPENCMW_FORCEINLINE std::int64_t addAndGet(std::int64_t value) noexcept {
4849
return std::atomic_fetch_add(&_fieldsValue, value) + value;
4950
}
5051
};

src/serialiser/include/IoBuffer.hpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
#pragma ide diagnostic ignored "cppcoreguidelines-owning-memory"
55
#pragma ide diagnostic ignored "UnreachableCode" // -- allow for alternate non-c-style memory management
66

7-
#include "MultiArray.hpp"
8-
#include "opencmw.hpp"
9-
107
#include <format>
118

129
#include <algorithm>
@@ -34,6 +31,10 @@ using polymorphic_allocator = std::experimental::pmr::polymorphic_allocator<T>;
3431
#include <utility>
3532
#include <vector>
3633

34+
#include <opencmw.hpp>
35+
36+
#include "MultiArray.hpp"
37+
3738
namespace opencmw {
3839

3940
/* special memory resource which explicitly uses malloc, free and allows the containers
@@ -210,7 +211,7 @@ struct IoBuffer {
210211
}
211212

212213
template<MetaInfo meta = WITH, typename Container>
213-
forceinline constexpr void putBoolContainer(const Container &values) noexcept {
214+
OPENCMW_FORCEINLINE constexpr void putBoolContainer(const Container &values) noexcept {
214215
const std::size_t size = values.size();
215216
const std::size_t byteToCopy = size * sizeof(bool);
216217
if constexpr (meta == WITH) {
@@ -308,7 +309,7 @@ struct IoBuffer {
308309
constexpr void clear() noexcept { _position = _size = 0; }
309310

310311
template<bool checkRange = true>
311-
forceinline constexpr void skip(int bytes) noexcept(!checkRange) {
312+
OPENCMW_FORCEINLINE constexpr void skip(int bytes) noexcept(!checkRange) {
312313
if constexpr (checkRange) {
313314
if (_position + static_cast<std::size_t>(bytes) > size()) { // catches both over and underflow
314315
throw std::out_of_range(std::format("requested index {} is out-of-range [0,{}]", static_cast<std::ptrdiff_t>(_position) + bytes, _size));
@@ -318,7 +319,7 @@ struct IoBuffer {
318319
}
319320

320321
template<typename R, bool checkRange = true>
321-
forceinline constexpr R &at(const size_t index) noexcept(!checkRange) {
322+
OPENCMW_FORCEINLINE constexpr R &at(const size_t index) noexcept(!checkRange) {
322323
if constexpr (checkRange) {
323324
if (index >= _size) {
324325
throw std::out_of_range(std::format("requested index {} is out-of-range [0,{}]", index, _size));
@@ -351,7 +352,7 @@ struct IoBuffer {
351352
}
352353

353354
template<MetaInfo meta = WITH, Number I>
354-
forceinline constexpr void put(const I &value) noexcept {
355+
OPENCMW_FORCEINLINE constexpr void put(const I &value) noexcept {
355356
constexpr std::size_t byteToCopy = sizeof(I);
356357
reserve_spare(byteToCopy);
357358

@@ -360,7 +361,7 @@ struct IoBuffer {
360361
}
361362

362363
template<MetaInfo meta = WITH, StringLike I>
363-
forceinline constexpr void put(const I &value) noexcept {
364+
OPENCMW_FORCEINLINE constexpr void put(const I &value) noexcept {
364365
const std::size_t bytesToCopy = value.size() * sizeof(char);
365366
reserve_spare(bytesToCopy + sizeof(int32_t) + sizeof(char)); // educated guess
366367
if constexpr (meta == WITH) {
@@ -376,24 +377,24 @@ struct IoBuffer {
376377
}
377378

378379
template<SupportedType I, size_t size>
379-
forceinline constexpr void put(I const (&values)[size]) noexcept { put(std::span<const I>(values, size)); } // NOLINT int a[30]; OK <-> std::array<int, 30>
380+
OPENCMW_FORCEINLINE constexpr void put(I const (&values)[size]) noexcept { put(std::span<const I>(values, size)); } // NOLINT int a[30]; OK <-> std::array<int, 30>
380381
template<SupportedType I>
381-
forceinline constexpr void put(std::vector<I> const &values) noexcept { put(std::span<const I>(values.data(), values.size())); }
382+
OPENCMW_FORCEINLINE constexpr void put(std::vector<I> const &values) noexcept { put(std::span<const I>(values.data(), values.size())); }
382383
template<SupportedType I, size_t size>
383-
forceinline constexpr void put(std::array<I, size> const &values) noexcept { put(std::span<const I>(values.data(), values.size())); }
384+
OPENCMW_FORCEINLINE constexpr void put(std::array<I, size> const &values) noexcept { put(std::span<const I>(values.data(), values.size())); }
384385

385386
template<MetaInfo meta = WITH>
386-
forceinline constexpr void put(std::vector<bool> const &values) noexcept {
387+
OPENCMW_FORCEINLINE constexpr void put(std::vector<bool> const &values) noexcept {
387388
putBoolContainer<meta>(values);
388389
}
389390

390391
template<MetaInfo meta = WITH, size_t size>
391-
forceinline constexpr void put(std::array<bool, size> const &values) noexcept {
392+
OPENCMW_FORCEINLINE constexpr void put(std::array<bool, size> const &values) noexcept {
392393
putBoolContainer<meta>(values);
393394
}
394395

395396
template<bool checkRange = true>
396-
[[nodiscard]] forceinline constexpr std::string_view asString(const size_t index = 0U, const int requestedSize = -1) const noexcept(!checkRange) {
397+
[[nodiscard]] OPENCMW_FORCEINLINE constexpr std::string_view asString(const size_t index = 0U, const int requestedSize = -1) const noexcept(!checkRange) {
397398
const auto unsigned_size = static_cast<std::size_t>(requestedSize);
398399
if constexpr (checkRange) {
399400
if (index > _size) {
@@ -410,7 +411,7 @@ struct IoBuffer {
410411
}
411412

412413
template<typename R, typename RawType = std::remove_cvref_t<R>>
413-
[[nodiscard]] forceinline constexpr R get() const noexcept {
414+
[[nodiscard]] OPENCMW_FORCEINLINE constexpr R get() const noexcept {
414415
if constexpr (Number<R>) {
415416
const std::size_t localPosition = _position;
416417
_position += sizeof(R);
@@ -427,7 +428,7 @@ struct IoBuffer {
427428
}
428429

429430
template<ArrayOrVector Container, bool checkRange = false>
430-
forceinline constexpr Container &getArray(Container &input, const std::size_t requestedSize = SIZE_MAX) const noexcept(!checkRange) {
431+
OPENCMW_FORCEINLINE constexpr Container &getArray(Container &input, const std::size_t requestedSize = SIZE_MAX) const noexcept(!checkRange) {
431432
using R = Container::value_type;
432433
const auto arraySize = std::min(static_cast<std::size_t>(get<int32_t>()), _size - _position);
433434
const std::size_t minArraySize = std::min(arraySize, requestedSize);
@@ -456,14 +457,14 @@ struct IoBuffer {
456457
}
457458

458459
template<SupportedType R>
459-
forceinline constexpr std::vector<R> getArray(std::vector<R> &&input = std::vector<R>(), const std::size_t requestedSize = SIZE_MAX) noexcept { return getArray(input, requestedSize); }
460+
OPENCMW_FORCEINLINE constexpr std::vector<R> getArray(std::vector<R> &&input = std::vector<R>(), const std::size_t requestedSize = SIZE_MAX) noexcept { return getArray(input, requestedSize); }
460461
template<SupportedType R, std::size_t size>
461-
[[maybe_unused]] forceinline constexpr std::array<R, size> getArray(std::array<R, size> &&input = std::array<R, size>(), const std::size_t requestedSize = size) noexcept { return getArray(input, requestedSize); }
462+
[[maybe_unused]] OPENCMW_FORCEINLINE constexpr std::array<R, size> getArray(std::array<R, size> &&input = std::array<R, size>(), const std::size_t requestedSize = size) noexcept { return getArray(input, requestedSize); }
462463

463464
template<StringArray R, typename T = typename R::value_type>
464-
[[nodiscard]] forceinline constexpr R &get(R &input, const std::size_t requestedSize = SIZE_MAX) noexcept { return getArray(input, requestedSize); }
465+
[[nodiscard]] OPENCMW_FORCEINLINE constexpr R &get(R &input, const std::size_t requestedSize = SIZE_MAX) noexcept { return getArray(input, requestedSize); }
465466
template<StringArray R, typename T = typename R::value_type>
466-
[[nodiscard]] forceinline constexpr R get(R &&input = R(), const std::size_t requestedSize = SIZE_MAX) noexcept { return getArray(std::forward<R>(input), requestedSize); }
467+
[[nodiscard]] OPENCMW_FORCEINLINE constexpr R get(R &&input = R(), const std::size_t requestedSize = SIZE_MAX) noexcept { return getArray(std::forward<R>(input), requestedSize); }
467468
};
468469

469470
} // namespace opencmw

src/serialiser/include/IoSerialiser.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#ifndef OPENCMW_IOSERIALISER_H
22
#define OPENCMW_IOSERIALISER_H
33

4-
#include "IoBuffer.hpp"
5-
#include "MultiArray.hpp"
64
#include <list>
75
#include <map>
86
#include <queue>
97

8+
#include "IoBuffer.hpp"
9+
#include "MultiArray.hpp"
10+
11+
#include <opencmw.hpp>
12+
1013
#pragma clang diagnostic push
1114
#pragma ide diagnostic ignored "cppcoreguidelines-avoid-magic-numbers"
1215
#pragma ide diagnostic ignored "cppcoreguidelines-avoid-c-arrays"
@@ -144,7 +147,7 @@ struct IoSerialiser {
144147
};
145148

146149
template<ReflectableClass T>
147-
forceinline int32_t findMemberIndex(const std::string_view &fieldName) noexcept {
150+
OPENCMW_FORCEINLINE int32_t findMemberIndex(const std::string_view &fieldName) noexcept {
148151
static constexpr ConstExprMap<std::string_view, int32_t, refl::reflect<T>().members.size> m{ refl::util::map_to_array<std::pair<std::string_view, int32_t>>(refl::reflect<T>().members, [](auto field, auto index) {
149152
return std::pair<std::string_view, int32_t>(field.name.c_str(), index);
150153
}) };
@@ -232,7 +235,7 @@ struct FieldHeaderReader {
232235

233236
namespace detail {
234237

235-
forceinline void moveToFieldEndBufferPosition(IoBuffer &buffer, const FieldDescriptionLong &field) {
238+
OPENCMW_FORCEINLINE void moveToFieldEndBufferPosition(IoBuffer &buffer, const FieldDescriptionLong &field) {
236239
if (field.dataEndPosition != std::numeric_limits<size_t>::max()) {
237240
buffer.set_position(field.dataEndPosition);
238241
}

0 commit comments

Comments
 (0)