Skip to content

Commit

Permalink
c++23
Browse files Browse the repository at this point in the history
  • Loading branch information
ksergey committed Jun 10, 2024
1 parent e6fe447 commit faf3a5e
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 33 deletions.
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ endif()

include(cmake/TurboQHelpers.cmake)

if(NOT TARGET fmt::fmt)
add_subdirectory(deps/fmt)
endif()
if(NOT TARGET Boost::outcome)
add_subdirectory(deps/boost_outcome)
endif()
Expand Down
10 changes: 7 additions & 3 deletions code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ set(TargetName turboq)

add_library(${TargetName})
target_compile_features(${TargetName}
PUBLIC cxx_std_20)
PUBLIC cxx_std_23)
set_target_properties(${TargetName}
PROPERTIES
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF)
target_compile_options(${TargetName}
PUBLIC -Wall -Wextra -Wattributes -Wpedantic -Wstrict-aliasing -Wcast-align -g)
# target_compile_options(${TargetName}
# PRIVATE -fno-rtti)
target_include_directories(${TargetName}
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(${TargetName}
PUBLIC Boost::outcome Boost::scope_exit fmt::fmt)
PUBLIC Boost::outcome Boost::scope_exit)

file(GLOB_RECURSE Sources "${CMAKE_CURRENT_SOURCE_DIR}/turboq/*.cpp")
file(GLOB_RECURSE Headers "${CMAKE_CURRENT_SOURCE_DIR}/turboq/*.h")
Expand All @@ -23,7 +27,7 @@ TurboQAddTestsFromSourceList(Sources
TurboQAddBenchmarksFromSourceList(Sources
PREFIX ${TargetName}
COMPILE_OPTIONS -Wall -Wextra -g
LIBS benchmark::benchmark_main ${TargetName} fmt::fmt)
LIBS benchmark::benchmark_main ${TargetName})

TurboQExcludeTestsAndBenchmarksFromSourceList(Sources)

Expand Down
5 changes: 2 additions & 3 deletions code/turboq/BoundedMPSCRawQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
#include <bit>
#include <cassert>
#include <cstddef>
#include <format>
#include <span>
#include <string_view>
#include <type_traits>

#include <fmt/format.h>

#include <turboq/MappedRegion.h>
#include <turboq/MemorySource.h>
#include <turboq/detail/math.h>
Expand Down Expand Up @@ -167,7 +166,7 @@ class BoundedMPSCRawQueueProducer {
std::size_t const totalSize = size + sizeof(MessageHeader);
if (totalSize > header_->maxMessageSize) [[unlikely]] {
throw std::runtime_error(
fmt::format("buffer exceed max message size ({} > {})", totalSize, header_->maxMessageSize));
std::format("buffer exceed max message size ({} > {})", totalSize, header_->maxMessageSize));
}

std::size_t currentProducerPos = std::atomic_ref(header_->producerPos).load(std::memory_order_acquire);
Expand Down
5 changes: 2 additions & 3 deletions code/turboq/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
#include <unistd.h>

#include <cassert>
#include <print>
#include <system_error>

#include <fmt/format.h>

namespace turboq {
namespace {

Expand Down Expand Up @@ -84,7 +83,7 @@ File::~File() noexcept {
auto const fd = fd_;
if (auto const result = closeNoThrow(); !result) {
if (result.assume_error().value() == EBADF) {
fmt::print(stderr, FMT_STRING("closing fd {}, it may already have been closed"), fd);
std::print(stderr, "closing fd {}, it may already have been closed\n", fd);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions code/turboq/MappedRegion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@

#include "MappedRegion.h"

#include <fmt/format.h>
#include <sys/mman.h>

#include <print>

namespace turboq {

MappedRegion::~MappedRegion() noexcept {
if (size_ > 0) {
if (::munmap(data_, size_) != 0) {
fmt::print(stderr, FMT_STRING("closing mapped region, it may be already unmapped\n"));
std::print(stderr, "closing mapped region, it may be already unmapped\n");
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions code/turboq/MemorySource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
#include <array>
#include <bit>
#include <charconv>
#include <print>
#include <ranges>
#include <regex>
#include <string_view>
#include <system_error>
#include <vector>

#include <boost/scope_exit.hpp>
#include <fmt/format.h>

namespace turboq {
namespace {
Expand Down Expand Up @@ -126,7 +126,7 @@ std::vector<MemoryMountPoint> readProcMounts() {
if (defaultHugePageSize) {
pageSize = defaultHugePageSize;
} else {
fmt::print(stderr, "pagesize option error for mount point \"{}\" ({}): {}\n", mntent.mnt_dir,
std::print(stderr, "pagesize option error for mount point \"{}\" ({}): {}\n", mntent.mnt_dir,
mntent.mnt_fsname, pageSize.assume_error().message());
continue;
}
Expand Down
15 changes: 7 additions & 8 deletions code/turboq/benchmark3_bm.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#include <atomic>
#include <barrier>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <format>
#include <numeric>
#include <print>
#include <thread>
#include <vector>

#include <benchmark/benchmark.h>

#include <fmt/format.h>

#include "BoundedMPSCRawQueue.h"
#include "BoundedSPMCRawQueue.h"
#include "BoundedSPSCRawQueue.h"
Expand Down Expand Up @@ -58,10 +59,8 @@ static void BM_EnqueueDequeue_NoThreads(::benchmark::State& state) {
std::uint64_t value = 0;

for (auto _ : state) {
while (!enqueue(producer, counter++)) {
}
while (!dequeue(consumer, value)) {
}
while (!enqueue(producer, counter++)) {}
while (!dequeue(consumer, value)) {}
assert(value == (counter - 1));
benchmark::DoNotOptimize(value);
}
Expand Down Expand Up @@ -118,7 +117,7 @@ inline void bindCurrentThreadToCore(int coreNo) noexcept {

auto const rc = ::pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
if (rc != 0) {
fmt::print(stderr, "failed to bind current thread to core: {}\n", ::strerror(rc));
std::print(stderr, "failed to bind current thread to core: {}\n", ::strerror(rc));
}
}

Expand Down Expand Up @@ -214,7 +213,7 @@ static void BM_EnqueueDequeue(::benchmark::State& state) {
std::uint64_t const expected = (Ops) * (Ops - 1) / 2;
std::uint64_t const actual = sum.load();
if (expected != actual) {
state.SkipWithError(fmt::format("Expected sum {}, got {}", expected, actual));
state.SkipWithError(std::format("Expected sum {}, got {}", expected, actual));
}
};
return runOnce<ProducersCount, ConsumersCount, BindToCoreT>(produceFn, consumeFn, endFn);
Expand Down
9 changes: 0 additions & 9 deletions deps/fmt/CMakeLists.txt

This file was deleted.

0 comments on commit faf3a5e

Please sign in to comment.