diff --git a/src/uvw/util.cpp b/src/uvw/util.cpp index 5dd5b186..1e5a6969 100644 --- a/src/uvw/util.cpp +++ b/src/uvw/util.cpp @@ -306,6 +306,10 @@ UVW_INLINE uint64_t utilities::constrained_memory() noexcept { return uv_get_constrained_memory(); } +UVW_INLINE uint64_t utilities::available_memory() noexcept { + return uv_get_available_memory(); +} + UVW_INLINE double utilities::uptime() noexcept { double ret; diff --git a/src/uvw/util.h b/src/uvw/util.h index 288e6334..6c955d96 100644 --- a/src/uvw/util.h +++ b/src/uvw/util.h @@ -86,6 +86,7 @@ using file_handle = details::uv_type_wrapper; /*!< Utility c using os_socket_handle = details::uv_type_wrapper; /*!< Utility class that wraps an os socket handle. */ using os_file_descriptor = details::uv_type_wrapper; /*!< Utility class that wraps an os file descriptor. */ using pid_type = details::uv_type_wrapper; /*!< Utility class that wraps a cross platform representation of a pid. */ +using clock_id = details::uvw_clock_id; /*!< Utility class that wraps a clock source. */ constexpr file_handle std_in{0}; /*!< Placeholder for stdin descriptor. */ constexpr file_handle std_out{1}; /*!< Placeholder for stdout descriptor. */ @@ -99,6 +100,7 @@ using gid_type = uv_gid_t; /*!< Library equivalent for uv_gid_t. */ using timeval = uv_timeval_t; /*!< Library equivalent for uv_timeval_t. */ using timeval64 = uv_timeval64_t; /*!< Library equivalent for uv_timeval64_t. */ +using timespec64 = uv_timespec64_t; /*!< Library equivalent for uv_timespec64_t. */ using resource_usage = uv_rusage_t; /*!< Library equivalent for uv_rusage_t. */ /** @@ -596,6 +598,12 @@ struct utilities { */ static uint64_t constrained_memory() noexcept; + /** + * @brief Gets the amount of free memory still available to the process. + * @return Amount of free memory still available to the process (in bytes). + */ + static uint64_t available_memory() noexcept; + /** * @brief Gets the current system uptime. * @return The current system uptime or 0 in case of errors. diff --git a/test/uvw/util.cpp b/test/uvw/util.cpp index de4d2a9c..7b705712 100644 --- a/test/uvw/util.cpp +++ b/test/uvw/util.cpp @@ -4,7 +4,9 @@ #include template -struct tag { using type = T; }; +struct tag { + using type = T; +}; TEST(Util, Utilities) { ASSERT_EQ(uvw::pid_type{}, uvw::pid_type{}); @@ -81,6 +83,8 @@ TEST(Util, Utilities) { ASSERT_NO_THROW(uvw::utilities::load_average()); ASSERT_NE(uvw::utilities::total_memory(), decltype(uvw::utilities::total_memory()){0}); + ASSERT_NE(uvw::utilities::constrained_memory(), decltype(uvw::utilities::constrained_memory()){0}); + ASSERT_NE(uvw::utilities::available_memory(), decltype(uvw::utilities::available_memory()){0}); ASSERT_NE(uvw::utilities::uptime(), decltype(uvw::utilities::uptime()){0}); ASSERT_NO_THROW(uvw::utilities::rusage()); ASSERT_NO_THROW(uvw::utilities::gettime(uvw::clock_id::MONOTONIC));