Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/cleanups clang format and ci #86

Merged
merged 6 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ jobs:
cxxstd: "11,14,17,2a"
addrmd: 64
cxxflags: "cxxflags=-Wa,-mbig-obj"
supported: "Too many unknowns to get this compiler working - gcc-8.1"
supported: true
os: windows-2019

needs: [runner-selection]
Expand Down
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-shebang-scripts-are-executable
- id: mixed-line-ending
args: [--fix=auto]


- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v17.0.2
hooks:
- id: clang-format
types_or: [c++, c, cuda]
30 changes: 25 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,32 @@ cmake_minimum_required(VERSION 3.5...3.16)

project(boost_lockfree VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)

option(BOOST_LOCKFREE_BUILD_TESTS "Build boost::lockfree tests" ${BUILD_TESTING})


add_library(boost_lockfree INTERFACE)
add_library(Boost::lockfree ALIAS boost_lockfree)

if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.23)
set(Headers
include/boost/lockfree/spsc_queue.hpp
include/boost/lockfree/policies.hpp
include/boost/lockfree/queue.hpp
include/boost/lockfree/lockfree_forward.hpp
include/boost/lockfree/detail/prefix.hpp
include/boost/lockfree/detail/copy_payload.hpp
include/boost/lockfree/detail/tagged_ptr_dcas.hpp
include/boost/lockfree/detail/tagged_ptr.hpp
include/boost/lockfree/detail/tagged_ptr_ptrcompression.hpp
include/boost/lockfree/detail/atomic.hpp
include/boost/lockfree/detail/freelist.hpp
include/boost/lockfree/detail/parameter.hpp
include/boost/lockfree/stack.hpp
)

target_sources(boost_lockfree PUBLIC FILE_SET HEADERS FILES ${Headers} )
endif()

target_include_directories(boost_lockfree INTERFACE include)

target_link_libraries(boost_lockfree
Expand All @@ -31,9 +54,6 @@ target_link_libraries(boost_lockfree
Boost::utility
)

if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")

add_subdirectory(test)

if( BOOST_LOCKFREE_BUILD_TESTS )
add_subdirectory(test)
endif()

147 changes: 147 additions & 0 deletions _clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
AccessModifierOffset: -4
AlignAfterOpenBracket: Align

# crashes: https://github.com/llvm/llvm-project/issues/55493
# AlignArrayOfStructures: Left

AlignConsecutiveAssignments: AcrossComments
AlignConsecutiveBitFields: AcrossComments
AlignConsecutiveDeclarations: AcrossComments
AlignConsecutiveMacros: AcrossComments
AlignConsecutiveShortCaseStatements:
Enabled: true
AcrossEmptyLines: true
AcrossComments: true
AlignCaseColons: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments:
Kind: Always
OverEmptyLines: 1

AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true

AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: true
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLambdasOnASingleLine: Empty
AllowShortLoopsOnASingleLine: false

AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BitFieldColonSpacing: Both
BraceWrapping:
AfterCaseLabel: false
AfterClass: true
AfterControlStatement: Never
AfterEnum: true
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakAfterAttributes: Leave
BreakBeforeInlineASMColon: Always
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterColon
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^!'
CompactNamespaces: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros: [ foreach, BOOST_FOREACH ]
IncludeBlocks: Preserve
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: false
IndentExternBlock: NoIndent
IndentGotoLabels: false
IndentPPDirectives: AfterHash
# IndentRequiresClause: true

IndentWidth: 4
IndentWrappedFunctionNames: false
InsertNewlineAtEOF: True
InsertTrailingCommas: Wrapped
# IntegerLiteralSeparator:
# Binary: 0
# Decimal: 3
# Hex: -1
KeepEmptyLinesAtTheStartOfBlocks: false
KeepEmptyLinesAtEOF: false
LambdaBodyIndentation: OuterScope
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
NamespaceMacros: [ MSGPACK_API_VERSION_NAMESPACE ]
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PPIndentWidth: 4
PackConstructorInitializers: Never
PenaltyBreakAssignment: 10
PenaltyBreakBeforeFirstCallParameter: 100
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 1200
PenaltyBreakString: 10
PenaltyBreakOpenParenthesis: 100
PenaltyExcessCharacter: 20
PenaltyReturnTypeOnItsOwnLine: 50
PointerAlignment: Left
ReferenceAlignment: Left
ReflowComments: true
RemoveParentheses: Leave

# NOTE: results in broken code
# RemoveSemicolon: true
# RequiresClausePosition: OwnLine
ShortNamespaceLines: 0
SortIncludes: CaseSensitive
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Always
SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInParentheses: true
SpacesInSquareBrackets: true
Standard: c++20
TabWidth: 8
UseTab: Never
WhitespaceSensitiveMacros: ['BOOST_PP_STRINGIZE']
38 changes: 19 additions & 19 deletions examples/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,58 @@
// http://www.boost.org/LICENSE_1_0.txt)

//[queue_example
#include <boost/thread/thread.hpp>
#include <boost/lockfree/queue.hpp>
#include <boost/thread/thread.hpp>
#include <iostream>

#include <boost/atomic.hpp>

boost::atomic_int producer_count(0);
boost::atomic_int consumer_count(0);
boost::atomic_int producer_count( 0 );
boost::atomic_int consumer_count( 0 );

boost::lockfree::queue<int> queue(128);
boost::lockfree::queue< int > queue( 128 );

const int iterations = 10000000;
const int iterations = 10000000;
const int producer_thread_count = 4;
const int consumer_thread_count = 4;

void producer(void)
void producer( void )
{
for (int i = 0; i != iterations; ++i) {
for ( int i = 0; i != iterations; ++i ) {
int value = ++producer_count;
while (!queue.push(value))
while ( !queue.push( value ) )
;
}
}

boost::atomic<bool> done (false);
void consumer(void)
boost::atomic< bool > done( false );
void consumer( void )
{
int value;
while (!done) {
while (queue.pop(value))
while ( !done ) {
while ( queue.pop( value ) )
++consumer_count;
}

while (queue.pop(value))
while ( queue.pop( value ) )
++consumer_count;
}

int main(int argc, char* argv[])
int main( int argc, char* argv[] )
{
using namespace std;
cout << "boost::lockfree::queue is ";
if (!queue.is_lock_free())
if ( !queue.is_lock_free() )
cout << "not ";
cout << "lockfree" << endl;

boost::thread_group producer_threads, consumer_threads;

for (int i = 0; i != producer_thread_count; ++i)
producer_threads.create_thread(producer);
for ( int i = 0; i != producer_thread_count; ++i )
producer_threads.create_thread( producer );

for (int i = 0; i != consumer_thread_count; ++i)
consumer_threads.create_thread(consumer);
for ( int i = 0; i != consumer_thread_count; ++i )
consumer_threads.create_thread( consumer );

producer_threads.join_all();
done = true;
Expand Down
32 changes: 16 additions & 16 deletions examples/spsc_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,52 @@
// http://www.boost.org/LICENSE_1_0.txt)

//[spsc_queue_example
#include <boost/thread/thread.hpp>
#include <boost/lockfree/spsc_queue.hpp>
#include <boost/thread/thread.hpp>
#include <iostream>

#include <boost/atomic.hpp>

int producer_count = 0;
boost::atomic_int consumer_count (0);
int producer_count = 0;
boost::atomic_int consumer_count( 0 );

boost::lockfree::spsc_queue<int, boost::lockfree::capacity<1024> > spsc_queue;
boost::lockfree::spsc_queue< int, boost::lockfree::capacity< 1024 > > spsc_queue;

const int iterations = 10000000;

void producer(void)
void producer( void )
{
for (int i = 0; i != iterations; ++i) {
for ( int i = 0; i != iterations; ++i ) {
int value = ++producer_count;
while (!spsc_queue.push(value))
while ( !spsc_queue.push( value ) )
;
}
}

boost::atomic<bool> done (false);
boost::atomic< bool > done( false );

void consumer(void)
void consumer( void )
{
int value;
while (!done) {
while (spsc_queue.pop(value))
while ( !done ) {
while ( spsc_queue.pop( value ) )
++consumer_count;
}

while (spsc_queue.pop(value))
while ( spsc_queue.pop( value ) )
++consumer_count;
}

int main(int argc, char* argv[])
int main( int argc, char* argv[] )
{
using namespace std;
cout << "boost::lockfree::queue is ";
if (!spsc_queue.is_lock_free())
if ( !spsc_queue.is_lock_free() )
cout << "not ";
cout << "lockfree" << endl;

boost::thread producer_thread(producer);
boost::thread consumer_thread(consumer);
boost::thread producer_thread( producer );
boost::thread consumer_thread( consumer );

producer_thread.join();
done = true;
Expand Down
Loading