Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Main
Synchronet
Compare Revisions
ab673a5c7126d72fffeb8b6f64bf183c9788c132...84a2bb321ffa35c33a731f8cb405785af556821f
Commits (1)
Add xp_timer64()
· 84a2bb32
Deucе
authored
Feb 12, 2022
This is a millisecond timer that tries to avoid floating-point operations.
84a2bb32
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
0 deletions
+37
-0
src/xpdev/genwrap.c
src/xpdev/genwrap.c
+36
-0
src/xpdev/genwrap.h
src/xpdev/genwrap.h
+1
-0
No files found.
src/xpdev/genwrap.c
View file @
84a2bb32
...
...
@@ -825,6 +825,42 @@ long double xp_timer(void)
return
(
ret
);
}
/****************************************************************************/
/* Returns the current value of the systems best timer (in MILLISECONDS) */
/* Any value < 0 indicates an error */
/****************************************************************************/
uint64_t
xp_timer64
(
void
)
{
uint64_t
ret
;
#if defined(__unix__)
struct
timespec
ts
;
if
(
clock_gettime
(
CLOCK_MONOTONIC
,
&
ts
)
==
0
)
{
ret
=
ts
.
tv_sec
*
1000
;
ret
+=
ts
.
tv_nsec
/
1000000
;
}
else
ret
=
-
1
;
#elif defined(_WIN32)
LARGE_INTEGER
freq
;
LARGE_INTEGER
tick
;
if
(
if
(
QueryPerformanceFrequency
(
&
freq
)
&&
QueryPerformanceCounter
(
&
tick
))
{
static
BOOL
intable
=
(
freq
%
1000
)
==
0
;
if
(
intable
)
ret
=
tick
.
QuadPart
/
(
freq
.
QuadPart
/
1000
);
else
ret
=
((
double
)
tick
.
QuadPart
)
/
(((
double
)
freq
.
QuadPart
)
/
1000
);
}
else
{
ret
=
GetTickCount
();
}
#else
#error no high-resolution time for this platform
#endif
return
(
ret
);
}
/* Returns TRUE if specified process is running */
BOOL
check_pid
(
pid_t
pid
)
{
...
...
src/xpdev/genwrap.h
View file @
84a2bb32
...
...
@@ -353,6 +353,7 @@ DLLEXPORT void xp_randomize(void);
DLLEXPORT
long
xp_random
(
int
);
DLLEXPORT
long
double
xp_timer
(
void
);
DLLEXPORT
uint64_t
xp_timer64
(
void
);
DLLEXPORT
char
*
os_version
(
char
*
str
);
DLLEXPORT
char
*
os_cmdshell
(
void
);
DLLEXPORT
char
*
lastchar
(
const
char
*
str
);
...
...