2023-08-03 17:30:57 +02:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// SPDX-FileCopyrightText: 2002-2006 Marcus Geelnard
|
|
|
|
// SPDX-FileCopyrightText: 2006-2017 Camilla Löwy <elmindreda@glfw.org>
|
|
|
|
// SPDX-FileCopyrightText: 2023 The Ebitengine Authors
|
2023-07-05 03:51:55 +02:00
|
|
|
|
2023-07-12 20:32:28 +02:00
|
|
|
//go:build freebsd || linux || netbsd || openbsd
|
|
|
|
|
2023-10-07 09:36:55 +02:00
|
|
|
#include "internal_unix.h"
|
2023-07-05 03:51:55 +02:00
|
|
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW internal API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Initialise timer
|
|
|
|
//
|
|
|
|
void _glfwInitTimerPOSIX(void)
|
|
|
|
{
|
|
|
|
#if defined(CLOCK_MONOTONIC)
|
|
|
|
struct timespec ts;
|
|
|
|
|
|
|
|
if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0)
|
|
|
|
{
|
|
|
|
_glfw.timer.posix.monotonic = GLFW_TRUE;
|
|
|
|
_glfw.timer.posix.frequency = 1000000000;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
_glfw.timer.posix.monotonic = GLFW_FALSE;
|
|
|
|
_glfw.timer.posix.frequency = 1000000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW platform API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
uint64_t _glfwPlatformGetTimerValue(void)
|
|
|
|
{
|
|
|
|
#if defined(CLOCK_MONOTONIC)
|
|
|
|
if (_glfw.timer.posix.monotonic)
|
|
|
|
{
|
|
|
|
struct timespec ts;
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
|
|
return (uint64_t) ts.tv_sec * (uint64_t) 1000000000 + (uint64_t) ts.tv_nsec;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
return (uint64_t) tv.tv_sec * (uint64_t) 1000000 + (uint64_t) tv.tv_usec;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t _glfwPlatformGetTimerFrequency(void)
|
|
|
|
{
|
|
|
|
return _glfw.timer.posix.frequency;
|
|
|
|
}
|
|
|
|
|