|
int pthread_wait_np (void)
当前周期的线程运行结束,总是返回0。
4.2.2 时间相关函数
RTLinux提供了一些时钟函数用于计时功能,包括线程调度,获得TSP(timestamps)等。
下面的是一般的计时函数:
/* #include <rtl_time.h> */
int clock_gettime(clockid_t clock_id, struct timespec *ts);
hrtime_t clock_gethrtime(clockid_t clock);
struct timespec {
time_t tv_sec; /* 秒 */
long tv_nsec; /* 纳秒 */
};
clock_gettime:读取当前的时间,保存到clock_id所指的对象中。
clock_gethrtime:读取当前时间,但返回一个64位(hrtime_t)的纳秒时间值。
一些时间转换的函数,用于把时间格式转换为另外一种格式。
时间转换函数:
/* #include <rtl_time.h> */
hrtime_t timespec_to_ns(const struct timespec *ts); /* timespec到纳秒数转换 */
struct timespec timespec_from_ns(hrtime_t t); /* 纳秒数到timespec转换 */
const struct timespec * hrt2ts(hrtime_t value); /*
下面是一些支持的时钟类型。
时钟类型相关的宏:
l CLOCK_MONOTONIC: POSIX时钟,以恒定速率运行;不会复位和调整
l CLOCK_REALTIME: 标准POSIX实时时钟。目前与CLOCK_MONOTONIC时钟相同
l CLOCK_RTL_SCHED: 调度器用来任务调度的时钟
以下是机器结构相关的时钟:
l CLOCK_8254: 在x86单处理器机器上用于调度的时钟
l CLOCK_APIC: 用在SMP x86机器的时钟
4.2.3 线程调度函数
RTLinux提供一些调度方式,允许线程代码在特定的时刻运行。RTLinux使用单纯优先级驱动的调度器,更搞优先级的线程总是被选择运行。如果两个线程的优先级拥有一样的优先级,选择那一个线程运行是不确定的。RTLinux使用下面的调度API:
int pthread_setschedparam (pthread_t thread, int policy, const struct sched_param *param)
设置一个线程的调度参数,用policy和sched_param两个参数设置thread的调度参数属性:
policy=SCHED_RR:使用Round-Robin方法调度
policy=SCHED_FIFO:使用先进先出的方法调度
返回0表示成功调度,非0表示失败。
int pthread_getschedparam (pthread_t thread, int policy, const struct sched_param *param)
上一页 [1] [2] [3] [4] [5] [6] [7] [8] 下一页 没有相关教程
|