From 7b7e478a8d50e52963ccf94817b3bbf5180567d2 Mon Sep 17 00:00:00 2001 From: Artur Mukhamadiev Date: Wed, 4 Jun 2025 18:05:34 +0000 Subject: [PATCH] [config][test] added .clang-format --- .clang-format | 1 + CMakeUserPresets.json | 2 +- compile_commands.json | 2 +- main.cc | 38 ++++++++++++++++++++------------------ 4 files changed, 23 insertions(+), 20 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..34fe704 --- /dev/null +++ b/.clang-format @@ -0,0 +1 @@ +BasedOnStyle: Chromium \ No newline at end of file diff --git a/CMakeUserPresets.json b/CMakeUserPresets.json index 71aeace..32e012f 100644 --- a/CMakeUserPresets.json +++ b/CMakeUserPresets.json @@ -4,6 +4,6 @@ "conan": {} }, "include": [ - "build/Release/generators/CMakePresets.json" + "build/Debug/generators/CMakePresets.json" ] } \ No newline at end of file diff --git a/compile_commands.json b/compile_commands.json index 195eeaf..2cb3529 120000 --- a/compile_commands.json +++ b/compile_commands.json @@ -1 +1 @@ -build/Release/compile_commands.json \ No newline at end of file +build/Debug/compile_commands.json \ No newline at end of file diff --git a/main.cc b/main.cc index 6dd86b6..415255d 100644 --- a/main.cc +++ b/main.cc @@ -4,31 +4,33 @@ static constexpr size_t repeat = 1 << 20; -void producer(moodycamel::ReaderWriterQueue& queue) { - for(int i = 0; i < repeat; ++i) { - while(!queue.try_enqueue(i)) { std::this_thread::yield(); } +void producer(moodycamel::ReaderWriterQueue& queue) { + std::string str{"10"}; + for (int i = 0; i < repeat; ++i) { + while (!queue.try_enqueue(str)) { + std::this_thread::yield(); } + } } -void consumer(moodycamel::ReaderWriterQueue& queue) { - size_t counter = 0; - int val = 0; - while(counter < repeat) { - while(!queue.try_dequeue(val)) { - std::this_thread::yield(); - } - ++counter; +void consumer(moodycamel::ReaderWriterQueue& queue) { + size_t counter = 0; + std::string val; + while (counter < repeat) { + while (!queue.try_dequeue(val)) { + std::this_thread::yield(); } + ++counter; + } } TEST(BASIC, rwq) { - moodycamel::ReaderWriterQueue queue; - std::jthread t1{&producer, std::ref(queue)}; - std::jthread t2{&consumer, std::ref(queue)}; + moodycamel::ReaderWriterQueue queue; + std::jthread t1{&producer, std::ref(queue)}; + std::jthread t2{&consumer, std::ref(queue)}; } -int main(int argc, char** argv) -{ - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); +int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } \ No newline at end of file