#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/mman.h>

#include <native/task.h>
#include <native/timer.h>

RT_TASK demo_task;

/* NOTE: error handling omitted. */

void demo(void *arg)
{
    RTIME now, previous;

/*
     * Arguments: &task (NULL=self),
     *            start time,
     *            period (here: 1 ms)
     */
    rt_task_set_periodic(NULL, TM_NOW, 1000000);
    previous = rt_timer_read();

while (1) {
        rt_task_wait_period(NULL);
        now = rt_timer_read();

/*
         * NOTE: printf may have unexpected impact on the timing of
         *       your program. It is used here in the critical loop
         *       only for demonstration purposes.
         */
        printf("Time since last turn: %ld.%06ld ms\n",
               (long)(now - previous) / 1000000,
               (long)(now - previous) % 1000000);
               previous = now;
    }
}

void catch_signal(int sig)
{
}

int main(int argc, char* argv[])
{
    signal(SIGTERM, catch_signal);
    signal(SIGINT, catch_signal);

/* Avoids memory swapping for this program */
    mlockall(MCL_CURRENT|MCL_FUTURE);

/*
     * Arguments: &task,
     *            name,
     *            stack size (0=default),
     *            priority,
     *            mode (FPU, start suspended, ...)
     */
    rt_task_create(&demo_task, "trivial", 0, 99, 0);

/*
     * Arguments: &task,
     *            task function,
     *            function argument
     */
    rt_task_start(&demo_task, &demo, NULL);

pause();

rt_task_delete(&demo_task);

return 0;
}

2 测试结果:

Time since last turn: 0.997940 ms                                               
Time since last turn: 1.001939 ms                                               
Time since last turn: 0.996909 ms                                               
Time since last turn: 1.000727 ms                                               
Time since last turn: 1.003576 ms                                               
Time since last turn: 1.000606 ms                                               
Time since last turn: 0.998909 ms                                               
Time since last turn: 0.998243 ms                                               
Time since last turn: 1.001333 ms                                               
Time since last turn: 0.997636 ms                                               
Time since last turn: 1.003152 ms                                               
Time since last turn: 0.996788 ms                                               
Time since last turn: 1.000060 ms                                               
Time since last turn: 0.998667 ms                                               
Time since last turn: 1.005030 ms                                               
Time since last turn: 0.995031 ms                                               
Time since last turn: 1.002545 ms                                               
Time since last turn: 1.002303 ms                                               
Time since last turn: 0.995515 ms                                               
Time since last turn: 1.002849 ms                                               
Time since last turn: 0.997878 ms                                               
Time since last turn: 1.002000 ms                                               
Time since last turn: 0.998546 ms                                               
Time since last turn: 0.999576 ms                                               
Time since last turn: 1.002363 ms                                               
Time since last turn: 0.998425 ms                                               
Time since last turn: 0.998969 ms                                               
Time since last turn: 1.000061 ms                                               
Time since last turn: 1.002788 ms                                               
Time since last turn: 0.996848 ms                                               
Time since last turn: 1.002182 ms                                               
Time since last turn: 0.999212 ms                                               
Time since last turn: 1.001455 ms                                               
Time since last turn: 0.997636 ms                                               
Time since last turn: 1.004546 ms                                               
Time since last turn: 0.995757 ms                                               
Time since last turn: 1.000788 ms                                               
Time since last turn: 0.998485 ms                                               
Time since last turn: 1.001333 ms                                               
Time since last turn: 0.998485 ms                                               
Time since last turn: 1.001152 ms                                               
Time since last turn: 0.999878 ms                                               
Time since last turn: 0.999334 ms                                               
Time since last turn: 1.002121 ms                                               
Time since last turn: 0.999697 ms                                               
Time since last turn: 1.000242 ms                                               
Time since last turn: 0.997697 ms                                               
Time since last turn: 1.000303 ms                                               
Time since last turn: 0.999879 ms                                               
Time since last turn: 1.000788 ms                                               
Time since last turn: 1.000061 ms                                               
Time since last turn: 0.999636 ms                                               
Time since last turn: 1.001454 ms                                               
Time since last turn: 0.997334 ms                                               
Time since last turn: 1.004666 ms                                               
Time since last turn: 0.996910 ms                                               
Time since last turn: 1.002545 ms                                               
Time since last turn: 0.996485 ms                                               
Time since last turn: 1.001273 ms                                               
Time since last turn: 0.998666 ms                                               
Time since last turn: 1.000788 ms                                               
Time since last turn: 0.999758 ms                                               
Time since last turn: 1.000242 ms                                               
Time since last turn: 0.999091 ms                                               
Time since last turn: 1.002909 ms                                               
Time since last turn: 1.000485 ms                                               
Time since last turn: 0.996424 ms                                               
Time since last turn: 1.001818 ms

linux - native task api 测试的更多相关文章

  1. API 测试的具体实现

    目录 API 测试的具体实现 基于 Spring Boot 构建的 API 使用 cURL 命令行工具进行测试 使用图形界面工具 Postman 进行测试 如何应对复杂场景的 API 测试? 总结 A ...

  2. node-webkit学习(4)Native UI API 之window

    node-webkit学习(4)Native UI API 之window 文/玄魂 目录 node-webkit学习(4)Native UI API 之window 前言 4.1  window a ...

  3. Java JVM、JNI、Native Function Interface、Create New Process Native Function API Analysis

    目录 . JAVA JVM . Java JNI: Java Native Interface . Java Create New Process Native Function API Analys ...

  4. Linux Native Aio 异步AIO的研究

    Linux Native Aio 异步AIO的研究 http://rango.swoole.com/archives/282 首先声明一下epoll+nonblock从宏观角度可以叫做全异步,但从微观 ...

  5. node-webkit教程<>Native UI API 之Menu(菜单)

    node-webkit教程(6)Native UI API 之Menu(菜单)1 前言... 2 6.1  Menu 概述... 3 6.2  menu api6 6.2.1  new Menu([o ...

  6. API测试工具SoapUI & Postman对比分析

    本文由葡萄城技术团队于博客园原创并首发 转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 最近公司要引入API测试工具,经过调查和了解,最终决定在SoapUI ...

  7. NODE-WEBKIT教程(6)NATIVE UI API 之MENU(菜单)

    node-webkit教程(6)Native UI API 之Menu(菜单) 文/玄魂 目录 node-webkit教程(6)Native UI API 之Menu(菜单) 前言 6.1  Menu ...

  8. NODE-WEBKIT教程(5)NATIVE UI API 之FRAMELESS WINDOW

    node-webkit教程(5)Native UI API 之Frameless window 文/玄魂 原文链接:http://www.xuanhun521.com/Blog/2014/4/15/n ...

  9. 如何选择API测试工具

    没有最好,只有最合适. 如今,越来越多的公司正在向DevOps的方向左转,以实现持续集成和持续部署开发.这意味着我们的反馈需要比以往更快,以便确定我们的应用程序是否准备好交付.这就是API测试如此重要 ...

随机推荐

  1. 了解Redis 和 Memcached 的区别

    1.Redis支持服务器端的数据操作:Redis相比Memcached来说,拥有更多的数据结构和并支持更丰富的数据操作,通常在Memcached里,你需要将数据拿到客户端来进行类似的修改再set回去. ...

  2. 转:sublime2 官方网址

    1. sublime2 官方网址 http://www.sublimetext.com/2

  3. 【pyhon】Python里的字符串查找函数find和java,js里的indexOf相似,找到返回序号,找不到返回-1

    # 例子: target='www.163.com' ')) ')==-1: print('263不存在于字符串'+target+'中') 运行: C:\Users\horn1\Desktop\pyt ...

  4. 0x8002801D:库没有注册

    同一段代码,在测试机上运行成功,但在用户机上运行失败,并报错:无法将类型为GeoProcessorClass的COM对象强制转换为接口类型IGeoProcessor,此操作失败的原因是COM组件调用Q ...

  5. 微信/易信公共平台开发(四):公众号调试器 (仿真微信平台,提供PHP源码)

    开发微信/易信公共平台时,调试往往很麻烦,一般只能在手机上边试边改, 或在服务器写日志.当你的服务器脚本有Bug时,手机上没有显示,追查是不容易的.我在开发过程中,编写了一个调试器, 能仿真微信/易信 ...

  6. PHP Libxml函数

    PHP Libxml 函数 PHP Libxml 简介 Libxml 函数和常量与 SimpleXML.XSLT 以及 DOM 函数一起使用. 安装 这些函数需要 Libxml 程序包. 在 xmls ...

  7. JDBC 利用反射技术将查询结果封装为对象(简单ORM实现)

    ORM(Object Relational Mapping)对象关系映射 public class ORMTest { public static void main(String[] args) t ...

  8. Jsp+Servlet+JavaBean经典MVC模式理解

    MVC模式目的(实现Web系统的职能分工). 在Java EE中,Jsp+Servlet+JavaBean算是里面经典的模式,是初学者必备的知识技能.M, Model(模型)实现系统的业务逻辑 1.通 ...

  9. phpredis中文手册——《redis中文手册》 php版(转)

    redis中文手册:http://readthedocs.org/docs/redis/en/latest/ 本文是参考<redis中文手册>,将示例代码用php来实现,注意php-red ...

  10. Android API之android.os.AsyncTask

    android.os.AsyncTask<Params, Progress, Result> AsyncTask enables proper and easy use of the UI ...