From 49b117f0c1d866c53a62f0467452f815727a20f1 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Tue, 19 May 2026 17:36:52 +0800 Subject: [PATCH 1/2] update clang-format --- .pre-commit-config.yaml | 2 +- include/boost/lockfree/queue.hpp | 1 - test/spsc_queue_test.cpp | 2 +- test/stack_test.cpp | 4 ++-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 26be932..606b6f6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,7 +10,7 @@ repos: args: [--fix=auto] - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v22.1.3 + rev: v22.1.5 hooks: - id: clang-format types_or: [c++, c, cuda] diff --git a/include/boost/lockfree/queue.hpp b/include/boost/lockfree/queue.hpp index 9f8c33d..17080ce 100644 --- a/include/boost/lockfree/queue.hpp +++ b/include/boost/lockfree/queue.hpp @@ -434,7 +434,6 @@ class queue #endif public: - /** Pops object from queue. * * \post if pop operation is successful, object will be copied to ret. diff --git a/test/spsc_queue_test.cpp b/test/spsc_queue_test.cpp index b3d79ca..0541051 100644 --- a/test/spsc_queue_test.cpp +++ b/test/spsc_queue_test.cpp @@ -498,7 +498,7 @@ BOOST_AUTO_TEST_CASE( spsc_queue_consume_all_test_compile_time ) f.push( 3 ); std::vector< int > consumed; - size_t count = f.consume_all( [&]( int i ) { + size_t count = f.consume_all( [ & ]( int i ) { consumed.push_back( i ); } ); diff --git a/test/stack_test.cpp b/test/stack_test.cpp index cb32058..0160eb6 100644 --- a/test/stack_test.cpp +++ b/test/stack_test.cpp @@ -337,7 +337,7 @@ BOOST_AUTO_TEST_CASE( stack_consume_all_atomic_order_test ) // consume_all_atomic pops all atomically and then processes in stack order (LIFO: 3, 2, 1) std::vector< int > consumed_order; - size_t consumed = f.consume_all_atomic( [&]( int i ) { + size_t consumed = f.consume_all_atomic( [ & ]( int i ) { consumed_order.push_back( i ); } ); @@ -361,7 +361,7 @@ BOOST_AUTO_TEST_CASE( stack_consume_all_atomic_reversed_order_test ) // consume_all_atomic_reversed processes in FIFO order (1, 2, 3) std::vector< int > consumed_order; - size_t consumed = f.consume_all_atomic_reversed( [&]( int i ) { + size_t consumed = f.consume_all_atomic_reversed( [ & ]( int i ) { consumed_order.push_back( i ); } ); From b8f45414df33035ea74cc75dc027eb1d0e94aadb Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Tue, 19 May 2026 19:21:38 +0800 Subject: [PATCH 2/2] use alignas instead of manual padding --- include/boost/lockfree/queue.hpp | 5 +---- include/boost/lockfree/spsc_queue.hpp | 8 +++----- include/boost/lockfree/stack.hpp | 5 +---- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/include/boost/lockfree/queue.hpp b/include/boost/lockfree/queue.hpp index 17080ce..9be5fb6 100644 --- a/include/boost/lockfree/queue.hpp +++ b/include/boost/lockfree/queue.hpp @@ -626,10 +626,7 @@ class queue private: #ifndef BOOST_DOXYGEN_INVOKED atomic< tagged_node_handle > head_; - static constexpr int padding_size = detail::cacheline_bytes - sizeof( tagged_node_handle ); - char padding1[ padding_size ]; - atomic< tagged_node_handle > tail_; - char padding2[ padding_size ]; + alignas( detail::cacheline_bytes ) atomic< tagged_node_handle > tail_; pool_t pool; #endif diff --git a/include/boost/lockfree/spsc_queue.hpp b/include/boost/lockfree/spsc_queue.hpp index d60cfb2..b2a4fcc 100644 --- a/include/boost/lockfree/spsc_queue.hpp +++ b/include/boost/lockfree/spsc_queue.hpp @@ -42,11 +42,9 @@ class ringbuffer_base { #ifndef BOOST_DOXYGEN_INVOKED protected: - typedef std::size_t size_t; - static constexpr int padding_size = cacheline_bytes - sizeof( size_t ); - atomic< size_t > write_index_; - char padding1[ padding_size ]; /* force read_index and write_index to different cache lines */ - atomic< size_t > read_index_; + typedef std::size_t size_t; + alignas( cacheline_bytes ) atomic< size_t > write_index_; + alignas( cacheline_bytes ) atomic< size_t > read_index_; protected: ringbuffer_base( void ) : diff --git a/include/boost/lockfree/stack.hpp b/include/boost/lockfree/stack.hpp index a1eb9b3..b92ed61 100644 --- a/include/boost/lockfree/stack.hpp +++ b/include/boost/lockfree/stack.hpp @@ -803,10 +803,7 @@ class stack #ifndef BOOST_DOXYGEN_INVOKED detail::atomic< tagged_node_handle > tos; - static const int padding_size = detail::cacheline_bytes - sizeof( tagged_node_handle ); - char padding[ padding_size ]; - - pool_t pool; + alignas( detail::cacheline_bytes ) pool_t pool; #endif };