📄 os.h
字号:
*/
#endif /* PJ_HAS_EVENT_OBJ */
/* **************************************************************************/
/**
* @addtogroup PJ_TIME Time Data Type and Manipulation.
* @ingroup PJ_OS
* @{
* This module provides API for manipulating time.
*
* \section pj_time_examples_sec Examples
*
* For examples, please see:
* - \ref page_pjlib_sleep_test
*/
/**
* Get current time of day in local representation.
*
* @param tv Variable to store the result.
*
* @return zero if successfull.
*/
PJ_DECL(pj_status_t) pj_gettimeofday(pj_time_val *tv);
/**
* Parse time value into date/time representation.
*
* @param tv The time.
* @param pt Variable to store the date time result.
*
* @return zero if successfull.
*/
PJ_DECL(pj_status_t) pj_time_decode(const pj_time_val *tv, pj_parsed_time *pt);
/**
* Encode date/time to time value.
*
* @param pt The date/time.
* @param tv Variable to store time value result.
*
* @return zero if successfull.
*/
PJ_DECL(pj_status_t) pj_time_encode(const pj_parsed_time *pt, pj_time_val *tv);
/**
* Convert local time to GMT.
*
* @param tv Time to convert.
*
* @return zero if successfull.
*/
PJ_DECL(pj_status_t) pj_time_local_to_gmt(pj_time_val *tv);
/**
* Convert GMT to local time.
*
* @param tv Time to convert.
*
* @return zero if successfull.
*/
PJ_DECL(pj_status_t) pj_time_gmt_to_local(pj_time_val *tv);
/**
* @}
*/
/* **************************************************************************/
#if defined(PJ_TERM_HAS_COLOR) && PJ_TERM_HAS_COLOR != 0
/**
* @defgroup PJ_TERM Terminal
* @ingroup PJ_OS
* @{
*/
/**
* Set current terminal color.
*
* @param color The RGB color.
*
* @return zero on success.
*/
PJ_DECL(pj_status_t) pj_term_set_color(pj_color_t color);
/**
* Get current terminal foreground color.
*
* @return RGB color.
*/
PJ_DECL(pj_color_t) pj_term_get_color(void);
/**
* @}
*/
#endif /* PJ_TERM_HAS_COLOR */
/* **************************************************************************/
/**
* @defgroup PJ_TIMESTAMP High Resolution Timestamp
* @ingroup PJ_OS
* @{
*
* PJLIB provides <b>High Resolution Timestamp</b> API to access highest
* resolution timestamp value provided by the platform. The API is usefull
* to measure precise elapsed time, and can be used in applications such
* as profiling.
*
* The timestamp value is represented in cycles, and can be related to
* normal time (in seconds or sub-seconds) using various functions provided.
*
* \section pj_timestamp_examples_sec Examples
*
* For examples, please see:
* - \ref page_pjlib_sleep_test
* - \ref page_pjlib_timestamp_test
*/
/*
* High resolution timer.
*/
#if defined(PJ_HAS_HIGH_RES_TIMER) && PJ_HAS_HIGH_RES_TIMER != 0
/**
* Acquire high resolution timer value. The time value are stored
* in cycles.
*
* @param ts High resolution timer value.
* @return PJ_SUCCESS or the appropriate error code.
*
* @see pj_get_timestamp_freq().
*/
PJ_DECL(pj_status_t) pj_get_timestamp(pj_timestamp *ts);
/**
* Get high resolution timer frequency, in cycles per second.
*
* @param freq Timer frequency, in cycles per second.
* @return PJ_SUCCESS or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_get_timestamp_freq(pj_timestamp *freq);
/**
* Set timestamp from 32bit values.
* @param t The timestamp to be set.
* @param hi The high 32bit part.
* @param lo The low 32bit part.
*/
PJ_INLINE(void) pj_set_timestamp32(pj_timestamp *t, pj_uint32_t hi,
pj_uint32_t lo)
{
t->u32.hi = hi;
t->u32.lo = lo;
}
/**
* Compare timestamp t1 and t2.
* @param t1 t1.
* @param t2 t2.
* @return -1 if (t1 < t2), 1 if (t1 > t2), or 0 if (t1 == t2)
*/
PJ_INLINE(int) pj_cmp_timestamp(const pj_timestamp *t1, const pj_timestamp *t2)
{
#if PJ_HAS_INT64
if (t1->u64 < t2->u64)
return -1;
else if (t1->u64 > t2->u64)
return 1;
else
return 0;
#else
if (t1->u32.hi < t2->u32.hi ||
(t1->u32.hi == t2->u32.hi && t1->u32.lo < t2->u32.lo))
return -1;
else if (t1->u32.hi > t2->u32.hi ||
(t1->u32.hi == t2->u32.hi && t1->u32.lo > t2->u32.lo))
return 1;
else
return 0;
#endif
}
/**
* Add timestamp t2 to t1.
* @param t1 t1.
* @param t2 t2.
*/
PJ_INLINE(void) pj_add_timestamp(pj_timestamp *t1, const pj_timestamp *t2)
{
#if PJ_HAS_INT64
t1->u64 += t2->u64;
#else
pj_uint32_t old = t1->u32.lo;
t1->u32.hi += t2->u32.hi;
t1->u32.lo += t2->u32.lo;
if (t1->u32.lo < old)
++t1->u32.hi;
#endif
}
/**
* Add timestamp t2 to t1.
* @param t1 t1.
* @param t2 t2.
*/
PJ_INLINE(void) pj_add_timestamp32(pj_timestamp *t1, pj_uint32_t t2)
{
#if PJ_HAS_INT64
t1->u64 += t2;
#else
pj_uint32_t old = t1->u32.lo;
t1->u32.lo += t2;
if (t1->u32.lo < old)
++t1->u32.hi;
#endif
}
/**
* Substract timestamp t2 from t1.
* @param t1 t1.
* @param t2 t2.
*/
PJ_INLINE(void) pj_sub_timestamp(pj_timestamp *t1, const pj_timestamp *t2)
{
#if PJ_HAS_INT64
t1->u64 -= t2->u64;
#else
t1->u32.hi -= t2->u32.hi;
if (t1->u32.lo >= t2->u32.lo)
t1->u32.lo -= t2->u32.lo;
else {
t1->u32.lo -= t2->u32.lo;
--t1->u32.hi;
}
#endif
}
/**
* Substract timestamp t2 from t1.
* @param t1 t1.
* @param t2 t2.
*/
PJ_INLINE(void) pj_sub_timestamp32(pj_timestamp *t1, pj_uint32_t t2)
{
#if PJ_HAS_INT64
t1->u64 -= t2;
#else
if (t1->u32.lo >= t2)
t1->u32.lo -= t2;
else {
t1->u32.lo -= t2;
--t1->u32.hi;
}
#endif
}
/**
* Get the timestamp difference between t2 and t1 (that is t2 minus t1),
* and return a 32bit signed integer difference.
*/
PJ_INLINE(pj_int32_t) pj_timestamp_diff32(const pj_timestamp *t1,
const pj_timestamp *t2)
{
/* Be careful with the signess (I think!) */
#if PJ_HAS_INT64
pj_int64_t diff = t2->u64 - t1->u64;
return (pj_int32_t) diff;
#else
pj_int32 diff = t2->u32.lo - t1->u32.lo;
return diff;
#endif
}
/**
* Calculate the elapsed time, and store it in pj_time_val.
* This function calculates the elapsed time using highest precision
* calculation that is available for current platform, considering
* whether floating point or 64-bit precision arithmetic is available.
* For maximum portability, application should prefer to use this function
* rather than calculating the elapsed time by itself.
*
* @param start The starting timestamp.
* @param stop The end timestamp.
*
* @return Elapsed time as #pj_time_val.
*
* @see pj_elapsed_usec(), pj_elapsed_cycle(), pj_elapsed_nanosec()
*/
PJ_DECL(pj_time_val) pj_elapsed_time( const pj_timestamp *start,
const pj_timestamp *stop );
/**
* Calculate the elapsed time as 32-bit miliseconds.
* This function calculates the elapsed time using highest precision
* calculation that is available for current platform, considering
* whether floating point or 64-bit precision arithmetic is available.
* For maximum portability, application should prefer to use this function
* rather than calculating the elapsed time by itself.
*
* @param start The starting timestamp.
* @param stop The end timestamp.
*
* @return Elapsed time in milisecond.
*
* @see pj_elapsed_time(), pj_elapsed_cycle(), pj_elapsed_nanosec()
*/
PJ_DECL(pj_uint32_t) pj_elapsed_msec( const pj_timestamp *start,
const pj_timestamp *stop );
/**
* Calculate the elapsed time in 32-bit microseconds.
* This function calculates the elapsed time using highest precision
* calculation that is available for current platform, considering
* whether floating point or 64-bit precision arithmetic is available.
* For maximum portability, application should prefer to use this function
* rather than calculating the elapsed time by itself.
*
* @param start The starting timestamp.
* @param stop The end timestamp.
*
* @return Elapsed time in microsecond.
*
* @see pj_elapsed_time(), pj_elapsed_cycle(), pj_elapsed_nanosec()
*/
PJ_DECL(pj_uint32_t) pj_elapsed_usec( const pj_timestamp *start,
const pj_timestamp *stop );
/**
* Calculate the elapsed time in 32-bit nanoseconds.
* This function calculates the elapsed time using highest precision
* calculation that is available for current platform, considering
* whether floating point or 64-bit precision arithmetic is available.
* For maximum portability, application should prefer to use this function
* rather than calculating the elapsed time by itself.
*
* @param start The starting timestamp.
* @param stop The end timestamp.
*
* @return Elapsed time in nanoseconds.
*
* @see pj_elapsed_time(), pj_elapsed_cycle(), pj_elapsed_usec()
*/
PJ_DECL(pj_uint32_t) pj_elapsed_nanosec( const pj_timestamp *start,
const pj_timestamp *stop );
/**
* Calculate the elapsed time in 32-bit cycles.
* This function calculates the elapsed time using highest precision
* calculation that is available for current platform, considering
* whether floating point or 64-bit precision arithmetic is available.
* For maximum portability, application should prefer to use this function
* rather than calculating the elapsed time by itself.
*
* @param start The starting timestamp.
* @param stop The end timestamp.
*
* @return Elapsed time in cycles.
*
* @see pj_elapsed_usec(), pj_elapsed_time(), pj_elapsed_nanosec()
*/
PJ_DECL(pj_uint32_t) pj_elapsed_cycle( const pj_timestamp *start,
const pj_timestamp *stop );
#endif /* PJ_HAS_HIGH_RES_TIMER */
/** @} */
/* **************************************************************************/
/**
* Internal PJLIB function to initialize the threading subsystem.
* @return PJ_SUCCESS or the appropriate error code.
*/
pj_status_t pj_thread_init(void);
PJ_END_DECL
#endif /* __PJ_OS_H__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -