netbsd源码(5)
来源:互联网 发布:centos 解压缩 tar.gz 编辑:程序博客网 时间:2024/06/02 05:29
本博客所有内容是原创,如果转载请注明来源
http://blog.csdn.net/myhaspl/
/*-
* Background information:
*
* When converting between timestamps on parallel timescales of differing
* resolutions it is historical and scientific practice to round down rather
* than doing 4/5 rounding.
*
* The date changes at midnight, not at noon.
*
* Even at 15:59:59.999999999 it's not four'o'clock.
*
* time_second ticks after N.999999999 not after N.4999999999
*/
在多个平行时间度量的时间戳中进行转换,这是一个有根据的和科学的一轮操作,这比四舍五入要好。
bintime转刚才的秒与纳秒格式。
static __inline void
bintime2timespec(const struct bintime *bt, struct timespec *ts)
{
ts->tv_sec = bt->sec;
ts->tv_nsec =
(long)(((uint64_t)1000000000 * (uint32_t)(bt-bintime的加法
static __inline void
bintime_add(struct bintime *bt, const struct bintime *bt2)
{
uint64_t u;
u = bt->frac;
bt->frac += bt2-bt->sec--;
bt->sec -= bt2->sec;
/*-
* Background information:
*
* When converting between timestamps on parallel timescales of differing
* resolutions it is historical and scientific practice to round down rather
* than doing 4/5 rounding.
*
* The date changes at midnight, not at noon.
*
* Even at 15:59:59.999999999 it's not four'o'clock.
*
* time_second ticks after N.999999999 not after N.4999999999
*/
在多个平行时间度量的时间戳中进行转换,这是一个有根据的和科学的一轮操作,这比四舍五入要好。
bintime转刚才的秒与纳秒格式。
static __inline void
bintime2timespec(const struct bintime *bt, struct timespec *ts)
{
ts->tv_sec = bt->sec;
ts->tv_nsec =
(long)(((uint64_t)1000000000 * (uint32_t)(bt->frac >> 32)) >> 32);
}
秒与纳秒转bintime
static __inline void
timespec2bintime(const struct timespec *ts, struct bintime *bt)
{
bt->sec = ts->tv_sec;
/* 18446744073 = int(2^64 / 1000000000) */
bt->frac = ts->tv_nsec * (uint64_t)18446744073LL;
}
bintime转秒和微秒
bintime
static __inline void
bintime2timeval(const struct bintime *bt, struct timeval *tv)
{
tv->tv_sec = bt->sec;
tv->tv_usec =
(suseconds_t)(((uint64_t)1000000 * (uint32_t)(bt->frac >> 32)) >> 32);
}
秒与微秒转bintime
static __inline void
timeval2bintime(const struct timeval *tv, struct bintime *bt)
{
bt->sec = tv->tv_sec;
/* 18446744073709 = int(2^64 / 1000000) */
bt->frac = tv->tv_usec * (uint64_t)18446744073709LL;
}
#endif /* !defined(_STANDALONE) *}
接着是POSIX 标准的实时部分(POSIX.1b)中时间的操作。
/* Operations on timespecs. */
清除
#define timespecclear(tsp) (tsp)->tv_sec = (time_t)((tsp)->tv_nsec = 0L)
检测是否设置,即是否为空。
#define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec)
比较
#define timespeccmp(tsp, usp, cmp) \
(((tsp)->tv_sec == (usp)->tv_sec) ? \
((tsp)->tv_nsec cmp (usp)->tv_nsec) : \
((tsp)->tv_sec cmp (usp)->tv_sec))
相加
#define timespecadd(tsp, usp, vsp) \
do { \
(vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \
(vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \
if ((vsp)->tv_nsec >= 1000000000L) { \
(vsp)->tv_sec++; \
(vsp)->tv_nsec -= 1000000000L; \
} \
} while (/* CONSTCOND */ 0)
减少
#define timespecsub(tsp, usp, vsp) \
do { \
(vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \
(vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \
if ((vsp)->tv_nsec < 0) { \
(vsp)->tv_sec--; \
(vsp)->tv_nsec += 1000000000L; \
} \
} while (/* CONSTCOND */ 0)
时间中的秒转 纳秒(十亿分之一秒)
#define timespec2ns(x) (((uint64_t)(x)->tv_sec) * 1000000000L + (x)->tv_nsec)
#endif /* _NETBSD_SOURCE */
- netbsd源码(5)
- netbsd源码(3)
- netbsd源码分析(1)
- netbsd源码分析(2)
- NetBSD安装手册
- NetBSD的网络参数设置
- netbsd配置gnome桌面
- ifconfig源代码-NetBSD
- Something about NetBSD
- NETBSD实战体会
- freebsd, openbsd, netbsd
- NetBSD IPv6环境建立
- NetBSD安装后续工作
- SFU NFS NetBSD 配置
- NetBSD 网络配置
- NetBSD 用户与用户组
- NetBSD文件权限
- NetBSD查看文件大小
- sql分组排序‘乐观’排名
- java的输入
- 我的代码规范记录
- 攻克拖延症——经历记录与心得分享
- 【百度云开发】问题集锦
- netbsd源码(5)
- ARM-----RO、RW和ZI DATA
- C语言-fgets()篇2
- hibernate性能优化的几点建议
- 过TP驱动保护
- C++: Converting an MFC CString to a std::string
- hdu 题目4034 (floyd算法的理解变形)
- POJ 3133 Manhattan Wiring 解题报告(插头DP)
- 对Java高级程序员有益的十个网站