diff --git a/libs/audio/include/psemek/audio/channel.hpp b/libs/audio/include/psemek/audio/channel.hpp index 75081f07..c82f6e40 100644 --- a/libs/audio/include/psemek/audio/channel.hpp +++ b/libs/audio/include/psemek/audio/channel.hpp @@ -1,8 +1,14 @@ #pragma once -#include +#include + +#include +#ifdef __cpp_lib_atomic_shared_ptr + #include +#else + #include +#endif -#include #include namespace psemek::audio @@ -37,7 +43,11 @@ namespace psemek::audio } private: - std::atomic stream_; + #ifdef __cpp_lib_atomic_shared_ptr + std::atomic stream_; + #else + util::mutexed stream_; + #endif }; using channel_ptr = std::shared_ptr; diff --git a/libs/gfx/include/psemek/gfx/detail/stb_image_write.h b/libs/gfx/include/psemek/gfx/detail/stb_image_write.h index e4b32ed1..151eacaa 100644 --- a/libs/gfx/include/psemek/gfx/detail/stb_image_write.h +++ b/libs/gfx/include/psemek/gfx/detail/stb_image_write.h @@ -773,7 +773,7 @@ static int stbi_write_hdr_core(stbi__write_context *s, int x, int y, int comp, f #ifdef __STDC_LIB_EXT1__ len = sprintf_s(buffer, sizeof(buffer), "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x); #else - len = sprintf(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x); + len = snprintf(buffer, sizeof(buffer), "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x); #endif s->func(s->context, buffer, len); diff --git a/libs/journal/source/event.cpp b/libs/journal/source/event.cpp index 4ebc68c6..62d43b17 100644 --- a/libs/journal/source/event.cpp +++ b/libs/journal/source/event.cpp @@ -8,7 +8,7 @@ namespace psemek::journal std::string current_time() { - const auto now = std::chrono::high_resolution_clock::now(); + const auto now = std::chrono::system_clock::now(); return std::format("{:%FT%TZ}", now); } diff --git a/libs/log/source/log.cpp b/libs/log/source/log.cpp index a5eab065..4f070455 100644 --- a/libs/log/source/log.cpp +++ b/libs/log/source/log.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include #include diff --git a/libs/math/include/psemek/math/detail/array.hpp b/libs/math/include/psemek/math/detail/array.hpp index fd835628..2b5c15a8 100644 --- a/libs/math/include/psemek/math/detail/array.hpp +++ b/libs/math/include/psemek/math/detail/array.hpp @@ -3,6 +3,8 @@ #include #include +#include + namespace psemek::math::detail { @@ -43,6 +45,8 @@ namespace psemek::math::detail T data[N]; + type() = default; + type(dynamic_dimensions){} dynamic_dimensions dimensions() const { return {}; } @@ -59,6 +63,8 @@ namespace psemek::math::detail { static constexpr std::size_t size = 0; + type() = default; + type(dynamic_dimensions<0>){} dynamic_dimensions<0> dimensions() const { return {}; } diff --git a/libs/math/include/psemek/math/detail/array_2d.hpp b/libs/math/include/psemek/math/detail/array_2d.hpp index 98f0075f..1d53c32a 100644 --- a/libs/math/include/psemek/math/detail/array_2d.hpp +++ b/libs/math/include/psemek/math/detail/array_2d.hpp @@ -67,7 +67,7 @@ namespace psemek::math::detail : rows(dimensions.rows.size) {} - dynamic_dimensions_2d dimensions() const { return {.rows = rows}; } + dynamic_dimensions_2d dimensions() const { return {.rows = {rows}}; } T const * operator[](std::size_t) const { throw empty_array_exception{}; } T * operator[](std::size_t) { throw empty_array_exception{}; } @@ -103,7 +103,7 @@ namespace psemek::math::detail : columns(dimensions.columns.size) {} - dynamic_dimensions_2d<0, dynamic> dimensions() const { return {.columns = columns}; } + dynamic_dimensions_2d<0, dynamic> dimensions() const { return {.columns = {columns}}; } T const * operator[](std::size_t) const { throw empty_array_exception{}; } T * operator[](std::size_t) { throw empty_array_exception{}; } @@ -141,7 +141,7 @@ namespace psemek::math::detail , data(std::make_unique_for_overwrite(rows * columns)) {} - dynamic_dimensions_2d dimensions() const { return {.columns = columns}; } + dynamic_dimensions_2d dimensions() const { return {.columns = {columns}}; } T * operator[] (std::size_t row) { @@ -178,7 +178,7 @@ namespace psemek::math::detail , data(std::make_unique_for_overwrite(rows * columns)) {} - dynamic_dimensions_2d dimensions() const { return {.rows = rows}; } + dynamic_dimensions_2d dimensions() const { return {.rows = {rows}}; } T * operator[] (std::size_t row) { @@ -216,7 +216,7 @@ namespace psemek::math::detail , data(std::make_unique_for_overwrite(rows * columns)) {} - dynamic_dimensions_2d dimensions() const { return {.rows = rows, .columns = columns}; } + dynamic_dimensions_2d dimensions() const { return {.rows = {rows}, .columns = {columns}}; } T * operator[] (std::size_t row) { diff --git a/libs/math/include/psemek/math/point.hpp b/libs/math/include/psemek/math/point.hpp index d1dc97c1..afbc199f 100644 --- a/libs/math/include/psemek/math/point.hpp +++ b/libs/math/include/psemek/math/point.hpp @@ -26,9 +26,7 @@ namespace psemek::math : coords(dimensions) {} - point() - : coords({}) - {} + point() = default; explicit point(std::size_t size) requires (N == dynamic) : coords({.size = size}) @@ -37,7 +35,6 @@ namespace psemek::math template requires(N != dynamic && sizeof...(Args) == N && detail::all_convertible_to::value) point(Args && ... args) - : coords({}) { auto out = values().begin(); ((*out++ = args), ...); diff --git a/libs/math/include/psemek/math/vector.hpp b/libs/math/include/psemek/math/vector.hpp index 977f244a..d0319e5f 100644 --- a/libs/math/include/psemek/math/vector.hpp +++ b/libs/math/include/psemek/math/vector.hpp @@ -29,9 +29,7 @@ namespace psemek::math : coords(dimensions) {} - vector() - : coords({}) - {} + vector() = default; explicit vector(std::size_t size) requires (N == dynamic) : coords({.size = size}) @@ -40,7 +38,6 @@ namespace psemek::math template requires(N != dynamic && sizeof...(Args) == N && detail::all_convertible_to::value) vector(Args && ... args) - : coords({}) { auto out = values().begin(); ((*out++ = args), ...); diff --git a/libs/util/CMakeLists.txt b/libs/util/CMakeLists.txt index 1fe769d0..5d74b0ba 100644 --- a/libs/util/CMakeLists.txt +++ b/libs/util/CMakeLists.txt @@ -1,4 +1,6 @@ if(NOT (CMAKE_SYSTEM_NAME STREQUAL Emscripten)) + # Boost.Math is header-only + # Required for statistics.hpp find_package(Boost COMPONENTS math REQUIRED CONFIG) endif() diff --git a/libs/util/include/psemek/util/exception.hpp b/libs/util/include/psemek/util/exception.hpp index 48ada36c..8890529c 100644 --- a/libs/util/include/psemek/util/exception.hpp +++ b/libs/util/include/psemek/util/exception.hpp @@ -16,8 +16,7 @@ namespace psemek::util #else struct stacktrace { - template - friend Stream & operator << (Stream & stream, stacktrace) + friend std::ostream & operator << (std::ostream & stream, stacktrace) { stream << "(stacktrace disabled)\n"; return stream; diff --git a/libs/util/include/psemek/util/mutexed.hpp b/libs/util/include/psemek/util/mutexed.hpp new file mode 100644 index 00000000..da0373b2 --- /dev/null +++ b/libs/util/include/psemek/util/mutexed.hpp @@ -0,0 +1,53 @@ +#pragma once + +#include +#include + +namespace psemek::util +{ + + template + struct mutexed + { + mutexed() = default; + + mutexed(mutexed const &) = delete; + mutexed(mutexed &&) = delete; + + mutexed & operator = (mutexed const &) = delete; + mutexed & operator = (mutexed &&) = delete; + + mutexed(T && value) + : value_(std::move(value)) + {} + + template + mutexed(std::in_place_t, Args && ... args) + : value_(std::forward(args)...) + {} + + T load() const + { + std::lock_guard lock{mutex_}; + return value_; + } + + void store(T && new_value) + { + std::lock_guard lock{mutex_}; + value_ = std::move(new_value); + } + + T exchange(T && new_value) + { + std::lock_guard lock{mutex_}; + std::swap(value_, new_value); + return new_value; + } + + private: + T value_; + mutable Mutex mutex_; + }; + +} diff --git a/libs/util/include/psemek/util/range.hpp b/libs/util/include/psemek/util/range.hpp index 35d1859f..a18c00ef 100644 --- a/libs/util/include/psemek/util/range.hpp +++ b/libs/util/include/psemek/util/range.hpp @@ -83,8 +83,8 @@ namespace psemek::util template auto reversed(Range const & r) { - auto it1 = begin(r); - auto it2 = end(r); + auto it1 = xbegin(r); + auto it2 = xend(r); using ReverseIterator = std::reverse_iterator; return range{std::make_reverse_iterator(it2), std::make_reverse_iterator(it1)}; diff --git a/package/CMakeLists.txt b/package/CMakeLists.txt index d8fb0d58..862baf91 100644 --- a/package/CMakeLists.txt +++ b/package/CMakeLists.txt @@ -59,9 +59,13 @@ function(psemek_add_executable_impl target is_application) target_link_libraries(${target} PUBLIC psemek) if(${is_application}) - target_link_libraries(${target} PUBLIC - "-Wl,--whole-archive $ -Wl,--no-whole-archive" - ${PSEMEK_BACKEND_LIBRARY}) + if(ANDROID) + target_link_libraries(${target} PUBLIC + "-Wl,--whole-archive $ -Wl,--no-whole-archive" + ${PSEMEK_BACKEND_LIBRARY}) + else() + target_link_libraries(${target} PUBLIC ${PSEMEK_BACKEND_LIBRARY}) + endif() endif() install(TARGETS ${target})