#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2013 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License // If the library is compiled as a DLL, this ensures symbols are exported #define NUCLEX_GAME_SOURCE 1 #include "Nuclex/Game/Config.h" #if defined(NUCLEX_GAME_LINUX) #include "Nuclex/Game/Timing/LinuxClock.h" #include #include #include #include namespace Nuclex { namespace Game { namespace Timing { // ------------------------------------------------------------------------------------------- // std::uint64_t LinuxClock::GetClockTime() { struct timespec time; int result = ::clock_gettime(CLOCK_MONOTONIC, &time); if(result != 0) { throw std::runtime_error("Could not query timer"); } std::uint64_t nanoseconds = static_cast(time.tv_sec) * 1000000000; nanoseconds += static_cast(time.tv_nsec); return nanoseconds; } // ------------------------------------------------------------------------------------------- // std::uint64_t LinuxClock::GetClockResolution() { struct timespec time; int result = ::clock_getres(CLOCK_MONOTONIC, &time); if(result != 0) { throw std::runtime_error("Could not query timer resolution"); } std::uint64_t nanoseconds = static_cast(time.tv_sec) * 1000000000; nanoseconds += static_cast(time.tv_nsec); return nanoseconds; } // ------------------------------------------------------------------------------------------- // std::uint64_t LinuxClock::GetWraparoundTime() const { // This isn't completely accurate. Normally we would need to find the gcd between // ((2 ^ 64) - 1) and (10 ^ 9) and modulo the time to that, but since the first wraparound // will happen no earlier than after 585 years of continuous uptime, we don't care. return std::numeric_limits::max(); } // ------------------------------------------------------------------------------------------- // std::uint64_t LinuxClock::GetTime() const { return LinuxClock::GetClockTime(); } // ------------------------------------------------------------------------------------------- // std::uint64_t LinuxClock::GetFrequency() const { return 1000000000; // This is the frequency, not the resolution! } // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Game::Timing #endif // defined(NUCLEX_GAME_LINUX)