Skip to content

Commit

Permalink
fix code review comments (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
kifir23917 committed Apr 27, 2024
1 parent 831b8cb commit eba02de
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions util/include/rusefi/rusefi_time_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static_assert(sizeof(efidurus_t) == 8);
/**
* 64 bit time in microseconds (1/1_000_000 of a second), since boot
*/
using efitimeus_t = std::chrono::time_point<std::chrono::system_clock, efidurus_t>;
using efitimeus_t = std::chrono::time_point<std::chrono::steady_clock, efidurus_t>;
static_assert(sizeof(efitimeus_t) == 8);

// time in seconds
Expand Down Expand Up @@ -59,19 +59,24 @@ efitick_t getTimeNowNt();
#define US_PER_SECOND_F 1000000.0
#define US_PER_SECOND_LL 1000000LL

template<typename arithmetic_type> constexpr efitimeus_t USOF(const arithmetic_type& us) {
static_assert(std::is_arithmetic_v<arithmetic_type>);
return efitimeus_t(efidurus_t(static_cast<efitimeus_t::rep>(us)));
template <typename T> concept numeric = std::integral<T> || std::floating_point<T>;

constexpr numeric auto MS2US(numeric auto ms_time) {
return ms_time * 1000;
}

constexpr float MS2US(const float& timems) {
return timems * 1000;
constexpr numeric auto US2MS(numeric auto timeus) {
return timeus / 1000;
}

constexpr efitimeus_t::rep US2MS(const efitimeus_t& timeus) {
return timeus.time_since_epoch().count() / 1000;
return timeus.time_since_epoch().count() / 1000;
}

constexpr float US2MS(const float& timeus) {
return timeus / 1000;
constexpr efitimeus_t USOF(std::integral auto us) {
return efitimeus_t(efidurus_t(us));
}

constexpr efitimeus_t::rep COUNTOF(const efitimeus_t& us) {
return us.time_since_epoch().count();
}

0 comments on commit eba02de

Please sign in to comment.