Merge remote-tracking branch 'lisyarus-dev/master' into web

This commit is contained in:
yulya3102 2026-07-02 21:58:28 +02:00
commit 923cb61012
13 changed files with 93 additions and 26 deletions

View file

@ -1,8 +1,14 @@
#pragma once
#include <psemek/audio/stream.hpp>
#include <version>
#include <psemek/audio/stream.hpp>
#ifdef __cpp_lib_atomic_shared_ptr
#include <atomic>
#else
#include <psemek/util/mutexed.hpp>
#endif
#include <atomic>
#include <memory>
namespace psemek::audio
@ -37,7 +43,11 @@ namespace psemek::audio
}
private:
std::atomic<stream_ptr> stream_;
#ifdef __cpp_lib_atomic_shared_ptr
std::atomic<stream_ptr> stream_;
#else
util::mutexed<stream_ptr> stream_;
#endif
};
using channel_ptr = std::shared_ptr<channel>;

View file

@ -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);

View file

@ -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);
}

View file

@ -2,7 +2,6 @@
#include <psemek/util/to_string.hpp>
#include <psemek/util/exception.hpp>
#include <psemek/util/hash_table.hpp>
#include <boost/stacktrace/stacktrace.hpp>
#include <chrono>
#include <ctime>

View file

@ -3,6 +3,8 @@
#include <psemek/math/dynamic.hpp>
#include <psemek/util/exception.hpp>
#include <memory>
namespace psemek::math::detail
{
@ -43,6 +45,8 @@ namespace psemek::math::detail
T data[N];
type() = default;
type(dynamic_dimensions<N>){}
dynamic_dimensions<N> 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 {}; }

View file

@ -67,7 +67,7 @@ namespace psemek::math::detail
: rows(dimensions.rows.size)
{}
dynamic_dimensions_2d<dynamic, 0> dimensions() const { return {.rows = rows}; }
dynamic_dimensions_2d<dynamic, 0> 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<T[]>(rows * columns))
{}
dynamic_dimensions_2d<R, dynamic> dimensions() const { return {.columns = columns}; }
dynamic_dimensions_2d<R, dynamic> 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<T[]>(rows * columns))
{}
dynamic_dimensions_2d<dynamic, C> dimensions() const { return {.rows = rows}; }
dynamic_dimensions_2d<dynamic, C> 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<T[]>(rows * columns))
{}
dynamic_dimensions_2d<dynamic, dynamic> dimensions() const { return {.rows = rows, .columns = columns}; }
dynamic_dimensions_2d<dynamic, dynamic> dimensions() const { return {.rows = {rows}, .columns = {columns}}; }
T * operator[] (std::size_t row)
{

View file

@ -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 <typename ... Args>
requires(N != dynamic && sizeof...(Args) == N && detail::all_convertible_to<T, Args...>::value)
point(Args && ... args)
: coords({})
{
auto out = values().begin();
((*out++ = args), ...);

View file

@ -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 <typename ... Args>
requires(N != dynamic && sizeof...(Args) == N && detail::all_convertible_to<T, Args...>::value)
vector(Args && ... args)
: coords({})
{
auto out = values().begin();
((*out++ = args), ...);

View file

@ -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()

View file

@ -16,8 +16,7 @@ namespace psemek::util
#else
struct stacktrace
{
template <typename Stream>
friend Stream & operator << (Stream & stream, stacktrace)
friend std::ostream & operator << (std::ostream & stream, stacktrace)
{
stream << "(stacktrace disabled)\n";
return stream;

View file

@ -0,0 +1,53 @@
#pragma once
#include <mutex>
#include <utility>
namespace psemek::util
{
template <typename T, typename Mutex = std::mutex>
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 <typename ... Args>
mutexed(std::in_place_t, Args && ... args)
: value_(std::forward<Args>(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_;
};
}

View file

@ -83,8 +83,8 @@ namespace psemek::util
template <typename Range>
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<decltype(it1)>;
return range<ReverseIterator>{std::make_reverse_iterator(it2), std::make_reverse_iterator(it1)};

View file

@ -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 $<TARGET_FILE:${PSEMEK_BACKEND_LIBRARY}> -Wl,--no-whole-archive"
${PSEMEK_BACKEND_LIBRARY})
if(ANDROID)
target_link_libraries(${target} PUBLIC
"-Wl,--whole-archive $<TARGET_FILE:${PSEMEK_BACKEND_LIBRARY}> -Wl,--no-whole-archive"
${PSEMEK_BACKEND_LIBRARY})
else()
target_link_libraries(${target} PUBLIC ${PSEMEK_BACKEND_LIBRARY})
endif()
endif()
install(TARGETS ${target})