Main Page
Related Pages
Modules
Classes
Files
File List
File Members
timing.c
Go to the documentation of this file.
1
/* ========================================================================== */
2
/*! \file
3
* \brief Timing related functions
4
*
5
* Copyright (c) 2012-2020 by the developers. See the LICENSE file for details.
6
*
7
* If nothing else is specified, function return zero to indicate success
8
* and a negative value to indicate an error.
9
*/
10
11
12
/* ========================================================================== */
13
/* Include headers */
14
15
#include "posix.h"
/* Include this first because of feature test macros */
16
17
#include <string.h>
18
19
#include "main.h"
20
#include "timing.h"
21
22
23
/* ========================================================================== */
24
/*! \defgroup TIMING TIME: Timing related convenience functions
25
*
26
* The functions are wrappers around POSIX \c nanosleep() .
27
*/
28
/*! @{ */
29
30
31
/* ========================================================================== */
32
/* Constants */
33
34
/*! \brief Message prefix for TIMING module */
35
#define MAIN_ERR_PREFIX "TIME: "
36
37
38
/* ========================================================================== */
39
/*! \brief Milisecond delay
40
*
41
* \param[in] msecs Number of miliseconds for delay
42
*
43
* \return
44
* - 0 on success
45
* - Negative value on error
46
*/
47
48
int
time_msleep
(
unsigned
int
msecs)
49
{
50
int
res;
51
struct_posix_timespec rqtp;
52
struct_posix_timespec rmtp;
53
54
/* Prepare requested value as the remaining interval */
55
rmtp.tv_sec = 0;
56
if
(1000U < msecs) { rmtp.tv_sec = (posix_time_t) (msecs / 1000U); }
57
rmtp.tv_nsec = (
long
int) (msecs % 1000U) * 1000000L;
58
59
/* Execute delay */
60
do
61
{
62
memcpy((
void
*) &rqtp, (
void
*) &rmtp,
sizeof
(struct_posix_timespec));
63
res = posix_nanosleep(&rqtp, &rmtp);
64
}
65
while
(-1 == res && POSIX_EINTR == posix_errno);
66
if
(-1 == res)
67
{
68
if
(POSIX_ENOSYS == posix_errno)
69
{
70
PRINT_ERROR
(
"nanosleep() not supported by operating system"
);
71
}
72
else
{
PRINT_ERROR
(
"msleep() failed"
); }
73
}
74
75
return
(res);
76
}
77
78
79
/*! @} */
80
81
/* EOF */
PRINT_ERROR
#define PRINT_ERROR(s)
Prepend module prefix and print error message.
Definition:
main.h:19
time_msleep
int time_msleep(unsigned int msecs)
Milisecond delay.
Definition:
timing.c:48
Generated at 2024-04-27 using