本博客所有内容是原创,如果转载请注明来源

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)相关推荐

  1. netbsd源码分析(1)

    今天想开始一个工程,分析NETBSD,工程比我想像的浩大,希望能在n个月内完成. NetBSD是一个免费的,具有高度移植性的 UNIX-like 操作系统,是现行可移植平台最多的操作系统,可以在许多平 ...

  2. 在 CentOS 7.0 上源码安装 Xen 4.5

    上周 CentOS 7.0 正式版发布了,Xen4CentOS 项目还没来得及更新支持 CentOS 7.0,所以目前要在 CentOS 7.0 上玩 Xen 的唯一办法只有编译源代码了.貌似这次 C ...

  3. zabbix源码安装实例

    环境 系统                 Centos7 zabbix版本      Zabbix 3.4.15 (revision 86739) zabbix源码安装 tar -zxvf zabb ...

  4. Android系统源码学习——源码目录结构介绍

    2019独角兽企业重金招聘Python工程师标准>>> Android 4.0源码目录结构: 本文介绍Android源码目录结构,以便读者理清Android编译系统核心代码在Andr ...

  5. 从os.cpus()来分析nodejs源码结构

    这几天和小伙伴在研究怎么用nodejs来监控机器的硬件信息,其中有项是要计算CPU的剩余idle信息,第一时间想到用top命令, 可以直接获取当前机器的硬件信息.本着好奇查了下top命令计算CPU i ...

  6. Android4.0源码目录结构详解

    Android4.0源码目录结构详解 Android4.0与2.1目录差不多 alsa这块,注意external/tinyalsa下有: include/tinyalsa/asoundlib.h mi ...

  7. 基于android2.3.5系统:源码下载及android体系架构

    **************************************************************************************************** ...

  8. android源码编译1

    一.环境说明: 1.liunx系统:Ubuntu12.04 2.jdk:sun-java6-jdk 3.g++4.5 gcc4.5 二.android源码的目录结构 |--Makefile|--bio ...

  9. Linux源码目录结构

    顶层: |-- Makefile #在顶层目录编译,利用的默认Makefile,它只是简单包含了build/core/main.mk |-- abi 应用二进制接口,不同的操作系统,应用二进制接口不同 ...

最新文章

  1. 2019 年ML NLP领域十大研究热点
  2. CCF-IFAA基金海外参展 全球安全盛会迎来中国声音
  3. 计算机视觉开源库OpenCV添加文字cv2.putText()参数详解
  4. 经典C语言程序100例之十七
  5. ASP.NET 3.5中的一个超简单的Ajax实验
  6. 混合云发展之路:前景广阔,巨头混战
  7. jmeter 压测 RabbitMQ_单机
  8. 【UOJ 50】树状数组2
  9. python不同时间周期k线_请问期货不同时间级别的k线呈现相反形态怎么判断买卖点?...
  10. httpclient 手写
  11. Docker 容器十诫
  12. 陀螺仪指向的是什么方向
  13. 鸿蒙2.0公测版支持机型,华为鸿蒙2.0露真容,公测版支持机型公布
  14. 蓝天模具风扇调速软件_联力UNI FAN SL120风扇体验:模组化拼装的风扇
  15. 测试案例分享:淘宝网用户体验测试出现的8个问题及测试方法公开
  16. 高盛:79页区块链报告-《从理论到实践》(附下载)
  17. 亚马逊云科技发布“云拓计划”赋能企业加速上云及数字化转型
  18. rsyslog搭建远程日志服务器
  19. PMI-PMP模考二错题解析(2022-01-21 21:46:29)
  20. 联想小新padpro怎么样?测评值得买吗?详细性能点评

热门文章

  1. wifi连接问题debug
  2. unity学习—打包apk打开手机摄像头插件Vuforia(非常简单)
  3. 出国整理行李的小窍门
  4. 【表达】Logic Thinking
  5. 突破百度云盘下载限制的Pandownload作者被抓,部分群众表示不满,百度云或将成为最大赢家?...
  6. 聊一聊系列之:面对秒杀
  7. UI设计规范(转载)
  8. 四川2020职称计算机考试副高,2020年教师职称普通副高和基层副高的区别?
  9. 想为你的手机壁纸了?最好的壁纸网站!
  10. 介绍几本超酷的COM的书籍