diff --git a/.gitmodules b/.gitmodules index 94e1d37..1984ae6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "lib/better-enums"] path = lib/better-enums url = https://github.com/aantron/better-enums +[submodule "lib/sprout"] + path = lib/sprout + url = https://github.com/bolero-MURAKAMI/Sprout.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ef6463..2a0e6d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,6 +106,7 @@ target_compile_features(${PROJECT_NAME} target_include_directories(${bare_name}-inc INTERFACE ${PROJECT_BINARY_DIR} INTERFACE ${CMAKE_SOURCE_DIR}/include + INTERFACE ${CMAKE_SOURCE_DIR}/lib/sprout ) diff --git a/include/helpers/lexical_cast.hpp b/include/helpers/lexical_cast.hpp index 7417892..f5bced8 100644 --- a/include/helpers/lexical_cast.hpp +++ b/include/helpers/lexical_cast.hpp @@ -21,10 +21,12 @@ #include "compatibility.h" #include "helpers/sequence_bt.hpp" #include "helpers/MaxSizedArray.hpp" +#include "sprout/math/log10.hpp" +#include "sprout/math/log2.hpp" +#include "sprout/math/pow.hpp" #include #include #include -#include #include #include #include @@ -112,7 +114,7 @@ namespace dinhelp { static std::size_t count_digits ( T parValue ) a_pure; static typename std::make_unsigned::type make_unsigned ( T parValue ) a_pure; static constexpr std::size_t count_digits_bt (std::size_t parNum) { - return (parNum == 0 ? 0 : static_cast(std::log10(static_cast(parNum)) / std::log10(static_cast(base)))) + 1; + return (parNum == 0 ? 0 : static_cast(sprout::log10(static_cast(parNum)) / sprout::log10(static_cast(base)))) + 1; } }; } //namespace implem @@ -133,7 +135,7 @@ namespace dinhelp { static typename std::make_unsigned::type make_unsigned ( T parValue ) a_pure; static constexpr std::size_t count_digits_bt (std::size_t parNum) { - return (parNum == 0 ? 0 : static_cast(std::log10(static_cast(parNum)))) + 1 + (std::numeric_limits::is_signed ? 1 : 0); + return (parNum == 0 ? 0 : static_cast(sprout::log10(static_cast(parNum)))) + 1 + (std::numeric_limits::is_signed ? 1 : 0); } }; @@ -153,7 +155,7 @@ namespace dinhelp { static std::size_t count_digits ( T parValue ) a_pure; static typename std::make_unsigned::type make_unsigned ( T parValue ) a_pure; static constexpr std::size_t count_digits_bt (std::size_t parNum) { - return (parNum == 0 ? 0 : static_cast(std::log2(static_cast(parNum)))) + 1; + return (parNum == 0 ? 0 : static_cast(sprout::log2(static_cast(parNum)))) + 1; } }; @@ -163,7 +165,7 @@ namespace dinhelp { std::size_t dec::count_digits_implem (T parValue, dinhelp::bt::index_seq, dinhelp::bt::index_seq) { typedef typename std::make_unsigned::type UT; static constexpr UT powers[] = { 0, static_cast(dinhelp::implem::power<10, Powers + 1>::value)... }; - static constexpr std::size_t maxdigits[] = { count_digits_bt(static_cast(::pow(2.0, Digits))) - (std::numeric_limits::is_signed ? 1 : 0)... }; + static constexpr std::size_t maxdigits[] = { count_digits_bt(static_cast(sprout::pow(2.0, Digits))) - (std::numeric_limits::is_signed ? 1 : 0)... }; const auto bits = sizeof(parValue) * CHAR_BIT - dinhelp::implem::count_leading_zeroes(dinhelp::implem::abs(parValue)); static_assert(std::is_same::value, "Unexpected type"); return (dinhelp::implem::abs(parValue) < powers[maxdigits[bits] - 1] ? maxdigits[bits] - 1 : maxdigits[bits]) + dinhelp::implem::is_negative::check(parValue); diff --git a/lib/sprout b/lib/sprout new file mode 160000 index 0000000..fea5e75 --- /dev/null +++ b/lib/sprout @@ -0,0 +1 @@ +Subproject commit fea5e752bda763c27ecd6f84531cdd0b4f82399d diff --git a/src/backends/redis/async_connection.cpp b/src/backends/redis/async_connection.cpp index cf48a01..483bc3c 100644 --- a/src/backends/redis/async_connection.cpp +++ b/src/backends/redis/async_connection.cpp @@ -36,13 +36,18 @@ namespace redis { ev_break(parLoop, EVBREAK_ALL); } - void lock_mutex_libev (ev_loop* parLoop) { + void lock_mutex_libev (ev_loop* parLoop) noexcept { std::mutex* mtx = static_cast(ev_userdata(parLoop)); assert(mtx); - mtx->lock(); + try { + mtx->lock(); + } + catch (const std::system_error&) { + assert(false); + } } - void unlock_mutex_libev (ev_loop* parLoop) { + void unlock_mutex_libev (ev_loop* parLoop) noexcept { std::mutex* mtx = static_cast(ev_userdata(parLoop)); assert(mtx); mtx->unlock();