RTEMS 6.1-rc4
Loading...
Searching...
No Matches
Files | Macros | Functions
Timespec Helpers

This group contains the implementation to support operations with variables of the POSIX defined struct timespec type. More...

Files

file  timespec.h
 This header file provides the interfaces of the Timespec Helpers.
 
file  timespecaddto.c
 This source file contains the implementation of _Timespec_Add_to().
 
file  timespecdivide.c
 This source file contains the implementation of _Timespec_Divide().
 
file  timespecdividebyinteger.c
 This source file contains the implementation of _Timespec_Divide_by_integer().
 
file  timespecfromticks.c
 This source file contains the implementation of _Timespec_From_ticks().
 
file  timespecgetasnanoseconds.c
 This source file contains the implementation of _Timespec_Get_as_nanoseconds().
 
file  timespecisnonnegative.c
 This source file contains the implementation of _Timespec_Is_non_negative().
 
file  timespecisvalid.c
 This source file contains the implementation of _Timespec_Is_valid().
 
file  timespeclessthan.c
 This source file contains the implementation of _Timespec_Less_than().
 
file  timespecsubtract.c
 This source file contains the implementation of _Timespec_Subtract().
 
file  timespectoticks.c
 This source file contains the implementation of _Timespec_To_ticks().
 

Macros

#define _Timespec_Set(_time, _seconds, _nanoseconds)
 Set timespec to seconds nanosecond.
 
#define _Timespec_Set_to_zero(_time)
 Sets the Timespec to Zero.
 
#define _Timespec_Get_seconds(_time)    ((_time)->tv_sec)
 Get seconds portion of timespec.
 
#define _Timespec_Get_nanoseconds(_time)    ((_time)->tv_nsec)
 Get nanoseconds portion of timespec.
 
#define _Timespec_Greater_than(_lhs, _rhs)    _Timespec_Less_than( _rhs, _lhs )
 The Timespec "greater than" operator.
 
#define _Timespec_Equal_to(lhs, rhs)
 The Timespec "equal to" operator.
 

Functions

uint64_t _Timespec_Get_as_nanoseconds (const struct timespec *time)
 Gets the timestamp as nanoseconds.
 
bool _Timespec_Is_non_negative (const struct timespec *time)
 Checks if the values in time are non-negative.
 
bool _Timespec_Is_valid (const struct timespec *time)
 Checks if timespec is valid.
 
bool _Timespec_Less_than (const struct timespec *lhs, const struct timespec *rhs)
 Checks if the left hand side timespec is less than the right one.
 
time_t _Timespec_Add_to (struct timespec *time, const struct timespec *add)
 Adds two timespecs.
 
uint32_t _Timespec_To_ticks (const struct timespec *time)
 Converts timespec to number of ticks.
 
void _Timespec_From_ticks (uint32_t ticks, struct timespec *time)
 Converts ticks to timespec.
 
void _Timespec_Subtract (const struct timespec *start, const struct timespec *end, struct timespec *result)
 Subtracts two timespec.
 
void _Timespec_Divide_by_integer (const struct timespec *time, uint32_t iterations, struct timespec *result)
 Divides timespec by an integer.
 
void _Timespec_Divide (const struct timespec *lhs, const struct timespec *rhs, uint32_t *ival_percentage, uint32_t *fval_percentage)
 Divides a timespec by another timespec.
 

Detailed Description

This group contains the implementation to support operations with variables of the POSIX defined struct timespec type.

Macro Definition Documentation

◆ _Timespec_Equal_to

#define _Timespec_Equal_to (   lhs,
  rhs 
)
Value:
( ((lhs)->tv_sec == (rhs)->tv_sec) && \
((lhs)->tv_nsec == (rhs)->tv_nsec) \
)

The Timespec "equal to" operator.

This method is the is equal to than operator for timespecs.

Parameters
[in]lhsis the left hand side timespec
[in]rhsis the right hand side timespec
Return values
Thismethod returns true if lhs is equal to rhs and false otherwise.

◆ _Timespec_Get_nanoseconds

#define _Timespec_Get_nanoseconds (   _time)     ((_time)->tv_nsec)

Get nanoseconds portion of timespec.

This method returns the nanoseconds portion of the specified timespec

Parameters
[in]_timepoints to the timespec
Return values
Thenanoseconds portion of _time.

◆ _Timespec_Get_seconds

#define _Timespec_Get_seconds (   _time)     ((_time)->tv_sec)

Get seconds portion of timespec.

This method returns the seconds portion of the specified timespec

Parameters
[in]_timepoints to the timespec
Return values
Theseconds portion of _time.

◆ _Timespec_Greater_than

#define _Timespec_Greater_than (   _lhs,
  _rhs 
)     _Timespec_Less_than( _rhs, _lhs )

The Timespec "greater than" operator.

This method is the greater than operator for timespecs.

Parameters
[in]_lhsis the left hand side timespec
[in]_rhsis the right hand side timespec
Return values
Thismethod returns true if lhs is greater than the rhs and false otherwise.

◆ _Timespec_Set

#define _Timespec_Set (   _time,
  _seconds,
  _nanoseconds 
)
Value:
do { \
(_time)->tv_sec = (_seconds); \
(_time)->tv_nsec = (_nanoseconds); \
} while (0)

Set timespec to seconds nanosecond.

This method sets the timespec to the specified seconds and nanoseconds value.

Parameters
[in]_timepoints to the timespec instance to validate.
[in]_secondsis the seconds portion of the timespec
[in]_nanosecondsis the nanoseconds portion of the timespec

◆ _Timespec_Set_to_zero

#define _Timespec_Set_to_zero (   _time)
Value:
do { \
(_time)->tv_sec = 0; \
(_time)->tv_nsec = 0; \
} while (0)

Sets the Timespec to Zero.

This method sets the timespec to zero. value.

Parameters
[in]_timepoints to the timespec instance to zero.

Function Documentation

◆ _Timespec_Add_to()

time_t _Timespec_Add_to ( struct timespec *  time,
const struct timespec *  add 
)

Adds two timespecs.

This routine adds two timespecs. The second argument is added to the first.

Parameters
timeThe base time to be added to.
addThe timespec to add to the first argument.
Returns
The number of seconds time increased by.

◆ _Timespec_Divide()

void _Timespec_Divide ( const struct timespec *  lhs,
const struct timespec *  rhs,
uint32_t *  ival_percentage,
uint32_t *  fval_percentage 
)

Divides a timespec by another timespec.

This routine divides a timespec by another timespec. The intended use is for calculating percentages to three decimal points.

Parameters
lhsThe left hand timespec.
rhsThe right hand timespec.
[out]ival_percentageThe integer portion of the average.
[out]fval_percentageThe thousandths of percentage.

◆ _Timespec_Divide_by_integer()

void _Timespec_Divide_by_integer ( const struct timespec *  time,
uint32_t  iterations,
struct timespec *  result 
)

Divides timespec by an integer.

This routine divides a timespec by an integer value. The expected use is to assist in benchmark calculations where you typically divide a duration by a number of iterations.

Parameters
timeThe total.
iterationsThe number of iterations.
[out]resultThe average time.

◆ _Timespec_From_ticks()

void _Timespec_From_ticks ( uint32_t  ticks,
struct timespec *  time 
)

Converts ticks to timespec.

This routine converts the ticks value to the corresponding timespec format time.

Parameters
ticksThe number of ticks to convert.
[out]timeThe timespec format time result.

◆ _Timespec_Get_as_nanoseconds()

uint64_t _Timespec_Get_as_nanoseconds ( const struct timespec *  time)

Gets the timestamp as nanoseconds.

This method returns the timestamp as nanoseconds.

Parameters
timepoints to the timestamp.
Returns
The time in nanoseconds.

◆ _Timespec_Is_non_negative()

bool _Timespec_Is_non_negative ( const struct timespec *  time)

Checks if the values in time are non-negative.

Parameters
[in]timeis the timespec instance to validate.
Return values
trueIf time is filled with non-negative values.
falseIf time is not filled with non-negative values.

◆ _Timespec_Is_valid()

bool _Timespec_Is_valid ( const struct timespec *  time)

Checks if timespec is valid.

This method determines the validity of a timespec.

Parameters
timeis the timespec instance to validate.
Return values
trueThe timespec is valid.
falseThe timespec is invalid.

◆ _Timespec_Less_than()

bool _Timespec_Less_than ( const struct timespec *  lhs,
const struct timespec *  rhs 
)

Checks if the left hand side timespec is less than the right one.

This method is the less than operator for timespecs.

Parameters
lhsis the left hand side timespec.
rhsis the right hand side timespec.
Return values
truelhs is less than rhs.
falselhs is greater than rhs.

◆ _Timespec_Subtract()

void _Timespec_Subtract ( const struct timespec *  start,
const struct timespec *  end,
struct timespec *  result 
)

Subtracts two timespec.

This routine subtracts two timespecs. result is set to end - start.

Parameters
startThe starting time
endThe ending time
[out]resultThe difference between starting and ending time.

◆ _Timespec_To_ticks()

uint32_t _Timespec_To_ticks ( const struct timespec *  time)

Converts timespec to number of ticks.

This routine convert the time timespec to the corresponding number of clock ticks.

Parameters
timeThe time to be converted.
Returns
The number of ticks computed.

This routines converts a timespec to the corresponding number of ticks.

We should ensure the ticks not be truncated by integer division. We need to have it be greater than or equal to the requested time. It should not be shorter.