From f8fda36b18d668b733a6e0bc5e771b8f09453c12 Mon Sep 17 00:00:00 2001 From: caomengxuan666 <2507560089@qq.com> Date: Mon, 9 Mar 2026 16:21:22 +0800 Subject: [PATCH] Fix BLOCK_SIZE macro conflict with system headers When including system headers like which define BLOCK_SIZE as a macro (usually 1024), it conflicts with the BLOCK_SIZE constant in concurrentqueue. This causes compilation errors. Add push/pop macro guards around the entire file to temporarily undefine BLOCK_SIZE if it exists, and restore it after. This is a common issue when using concurrentqueue with io_uring or other Linux headers that define BLOCK_SIZE. The fix uses #pragma push_macro/ pop_macro which is supported by GCC, Clang, and MSVC. --- blockingconcurrentqueue.h | 13 +++++++++++++ concurrentqueue.h | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/blockingconcurrentqueue.h b/blockingconcurrentqueue.h index 205a4db7..4c9174a8 100644 --- a/blockingconcurrentqueue.h +++ b/blockingconcurrentqueue.h @@ -7,6 +7,13 @@ #pragma once +// Work around potential conflict with system headers (e.g., ) that define BLOCK_SIZE as a macro +#ifdef BLOCK_SIZE +#pragma push_macro("BLOCK_SIZE") +#undef BLOCK_SIZE +#define CONCURRENTQUEUE_BLOCK_SIZE_WAS_DEFINED +#endif + #include "concurrentqueue.h" #include "lightweightsemaphore.h" @@ -580,3 +587,9 @@ inline void swap(BlockingConcurrentQueue& a, BlockingConcurrentQueue< } } // end namespace moodycamel + +// Restore BLOCK_SIZE macro if it was defined before +#ifdef CONCURRENTQUEUE_BLOCK_SIZE_WAS_DEFINED +#pragma pop_macro("BLOCK_SIZE") +#undef CONCURRENTQUEUE_BLOCK_SIZE_WAS_DEFINED +#endif diff --git a/concurrentqueue.h b/concurrentqueue.h index 9d00070f..d860a4f4 100644 --- a/concurrentqueue.h +++ b/concurrentqueue.h @@ -50,6 +50,13 @@ #pragma warning(disable: 4127) // conditional expression is constant #endif +// Work around potential conflict with system headers (e.g., ) that define BLOCK_SIZE as a macro +#ifdef BLOCK_SIZE +#pragma push_macro("BLOCK_SIZE") +#undef BLOCK_SIZE +#define CONCURRENTQUEUE_BLOCK_SIZE_WAS_DEFINED +#endif + #if defined(__APPLE__) #include "TargetConditionals.h" #endif @@ -3738,6 +3745,12 @@ inline void swap(typename ConcurrentQueue::ImplicitProducerKVP& a, ty } +// Restore BLOCK_SIZE macro if it was defined before +#ifdef CONCURRENTQUEUE_BLOCK_SIZE_WAS_DEFINED +#pragma pop_macro("BLOCK_SIZE") +#undef CONCURRENTQUEUE_BLOCK_SIZE_WAS_DEFINED +#endif + #if defined(_MSC_VER) && (!defined(_HAS_CXX17) || !_HAS_CXX17) #pragma warning(pop) #endif