From dbb90e51b0aec2bba242697a1d4defbc3d10df13 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Tue, 3 Oct 2017 14:39:02 +0200 Subject: [PATCH] Force inlining of the hot path. --- client/concurrentqueue.h | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/client/concurrentqueue.h b/client/concurrentqueue.h index 956c6959..4ff610e0 100755 --- a/client/concurrentqueue.h +++ b/client/concurrentqueue.h @@ -30,6 +30,14 @@ #pragma once +#if defined(__GNUC__) +# define force_inline __attribute__((always_inline)) +#elif defined(_MSC_VER) +# define force_inline __forceinline +#else +# define force_inline inline +#endif + #if defined(__GNUC__) // Disable -Wconversion warnings (spuriously triggered when Traits::size_t and // Traits::index_t are set to < 32 bits, causing integer promotion, causing warnings @@ -943,12 +951,12 @@ public: return inner_enqueue(token, std::move(item)); } - inline T* enqueue_begin(producer_token_t const& token) + force_inline T* enqueue_begin(producer_token_t const& token) { return inner_enqueue_begin(token); } - inline void enqueue_finish(producer_token_t const& token) + force_inline void enqueue_finish(producer_token_t const& token) { inner_enqueue_finish(token); } @@ -1293,12 +1301,12 @@ private: } template - inline T* inner_enqueue_begin(producer_token_t const& token) + force_inline T* inner_enqueue_begin(producer_token_t const& token) { return static_cast(token.producer)->ConcurrentQueue::ExplicitProducer::template enqueue_begin(); } - inline void inner_enqueue_finish(producer_token_t const& token) + force_inline void inner_enqueue_finish(producer_token_t const& token) { return static_cast(token.producer)->ConcurrentQueue::ExplicitProducer::template enqueue_finish(); } @@ -1968,7 +1976,7 @@ private: } template - inline T* enqueue_begin() + force_inline T* enqueue_begin() { pr_currentTailIndex = this->tailIndex.load(std::memory_order_relaxed); if ((pr_currentTailIndex & static_cast(BLOCK_SIZE - 1)) != 0) { @@ -1980,7 +1988,7 @@ private: } } - inline void enqueue_finish() + force_inline void enqueue_finish() { this->tailIndex.store(pr_currentTailIndex + 1, std::memory_order_release); }