mirror of
https://github.com/vanilla-wiiu/vanilla.git
synced 2025-01-22 08:11:47 -05:00
add get_millis() to util
This commit is contained in:
parent
e140c1a58c
commit
717dcbc6cd
2 changed files with 22 additions and 1 deletions
22
lib/util.c
22
lib/util.c
|
@ -1,9 +1,11 @@
|
|||
#include "util.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <math.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "status.h"
|
||||
|
@ -77,4 +79,22 @@ void name_thread(pthread_t thread, const char *name)
|
|||
if (ppthread_setname_np) {
|
||||
ppthread_setname_np(thread, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t get_millis()
|
||||
{
|
||||
size_t ms; // Milliseconds
|
||||
size_t s; // Seconds
|
||||
struct timespec spec;
|
||||
|
||||
clock_gettime(CLOCK_REALTIME, &spec);
|
||||
|
||||
s = spec.tv_sec;
|
||||
ms = round(spec.tv_nsec / 1.0e6); // Convert nanoseconds to milliseconds
|
||||
if (ms > 999) {
|
||||
s++;
|
||||
ms = 0;
|
||||
}
|
||||
|
||||
return (s * 1000) + ms;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ void force_interrupt();
|
|||
void install_interrupt_handler();
|
||||
void uninstall_interrupt_handler();
|
||||
void name_thread(pthread_t thread, const char *name);
|
||||
size_t get_millis();
|
||||
|
||||
uint16_t crc16(const void* data, size_t len);
|
||||
|
||||
|
|
Loading…
Reference in a new issue