Skip to content

Commit f8fda36

Browse files
Fix BLOCK_SIZE macro conflict with system headers
When including system headers like <linux/fs.h> 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.
1 parent 593df78 commit f8fda36

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

blockingconcurrentqueue.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77

88
#pragma once
99

10+
// Work around potential conflict with system headers (e.g., <linux/fs.h>) that define BLOCK_SIZE as a macro
11+
#ifdef BLOCK_SIZE
12+
#pragma push_macro("BLOCK_SIZE")
13+
#undef BLOCK_SIZE
14+
#define CONCURRENTQUEUE_BLOCK_SIZE_WAS_DEFINED
15+
#endif
16+
1017
#include "concurrentqueue.h"
1118
#include "lightweightsemaphore.h"
1219

@@ -580,3 +587,9 @@ inline void swap(BlockingConcurrentQueue<T, Traits>& a, BlockingConcurrentQueue<
580587
}
581588

582589
} // end namespace moodycamel
590+
591+
// Restore BLOCK_SIZE macro if it was defined before
592+
#ifdef CONCURRENTQUEUE_BLOCK_SIZE_WAS_DEFINED
593+
#pragma pop_macro("BLOCK_SIZE")
594+
#undef CONCURRENTQUEUE_BLOCK_SIZE_WAS_DEFINED
595+
#endif

concurrentqueue.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@
5050
#pragma warning(disable: 4127) // conditional expression is constant
5151
#endif
5252

53+
// Work around potential conflict with system headers (e.g., <linux/fs.h>) that define BLOCK_SIZE as a macro
54+
#ifdef BLOCK_SIZE
55+
#pragma push_macro("BLOCK_SIZE")
56+
#undef BLOCK_SIZE
57+
#define CONCURRENTQUEUE_BLOCK_SIZE_WAS_DEFINED
58+
#endif
59+
5360
#if defined(__APPLE__)
5461
#include "TargetConditionals.h"
5562
#endif
@@ -3738,6 +3745,12 @@ inline void swap(typename ConcurrentQueue<T, Traits>::ImplicitProducerKVP& a, ty
37383745

37393746
}
37403747

3748+
// Restore BLOCK_SIZE macro if it was defined before
3749+
#ifdef CONCURRENTQUEUE_BLOCK_SIZE_WAS_DEFINED
3750+
#pragma pop_macro("BLOCK_SIZE")
3751+
#undef CONCURRENTQUEUE_BLOCK_SIZE_WAS_DEFINED
3752+
#endif
3753+
37413754
#if defined(_MSC_VER) && (!defined(_HAS_CXX17) || !_HAS_CXX17)
37423755
#pragma warning(pop)
37433756
#endif

0 commit comments

Comments
 (0)