首页 > 代码库 > POSIX-Data Structure
POSIX-Data Structure
strcut sigevent
The <signal.h> header shall define the sigevent structure, which shall include at least the following members:
struct sigevent { int sigev_notify; //Notification type. int sigev_signo; //Signal number. union sigval sigev_value; //Signal value. void (*sigev_notify_function)(union sigval); //Notification function. pthread_attr_t *sigev_notify_attributes; //Notification attributes. };
sigev_notify
sigev_notify 的取值范围如下,只有3种情况(对应的宏在<signal.h>中定义)。
- SIGEV_NONE
- 事件发生时,什么也不做.
- SIGEV_SIGNAL
- 事件发生时,将sigev_signo 指定的信号(A queued signal)发送给指定的进程.
- SIGEV_THREAD
- 事件发生时,内核会(在此进程内)以sigev_notification_attributes为线程属性创建一个线程,并且让它执行sigev_notify_function,
- 传入sigev_value作为为一个参数.
sigev_signo
在sigev_notify = SIGEV_SIGNAL 时使用,指定信号的种别(number).
sigev_value
在sigev_notify = SIGEV_THREAD 时使用,作为sigev_notify_function 的参数.
union sigval{ int sival_int; void *sival_ptr;};
(*sigev_notify_function)(union sigval)
函数指针(指向通知执行函数),在sigev_notify = SIGEV_THREAD 时使用, 其他情况下置为NULL.
sigev_notify_attributes
指向线程属性的指针,在sigev_notify = SIGEV_THREAD 时使用,指定创建线程的属性, 其他情况下置为NULL.
struct timespec
The <time.h> header shall declare the timespec structure, which shall include at least the following members:
struct timespec { time_t tv_sec; /* Seconds */ long tv_nsec; /* Nanoseconds(纳秒:十亿分之一秒) */};
strcut itimerspec
The <time.h> header shall also declare the itimerspec structure, which shall include at least the following members:
struct itimerspec { struct timespec it_interval; /* Timer interval(timer循环时间间隔) */ struct timespec it_value; /* Initial expiration(timer初次到期时间) */};
clockid_t
clockid_t is used for clock ID type in the clock and timer functions, 取值范围如下(前4个是POSIX定义的,灰色部分为Linux的扩展),
/* Identifier for system-wide realtime clock, Setting this clock requires appropriate privileges */#define CLOCK_REALTIME 0/* Monotonic system-wide clock, Clock that cannot be set and represents monotonic time since some unspecified starting point */#define CLOCK_MONOTONIC 1/* High-resolution timer from the CPU. */#define 2/* Thread-specific CPU-time clock. */#define CLOCK_THREAD_CPUTIME_ID 3/* Monotonic system-wide clock, not adjusted for frequency scaling. */#define CLOCK_MONOTONIC_RAW 4/* Identifier for system-wide realtime clock, updated only on ticks. */#define CLOCK_REALTIME_COARSE 5/* Monotonic system-wide clock, updated only on ticks. */#define CLOCK_MONOTONIC_COARSE 6
CLOCK_REALTIME : 这种时钟表示的是绝对时间, 指的是从1970年1月1月0:00到目前经过多少秒, 相当于你的linux系统中显示的时间, 所以这个时间是可以更改的, 当系统的时钟源被改变,或者系统管理员重置了系统时间之后,这种类型的时钟可以得到相应的调整, 对设定为此类型的timer是有影响的.
CLOCK_MONOTONIC : 这种时钟表示的是相对时间, 其值对通过累积时钟节拍(嘀嗒)计算出来的, 不受时钟源等的影响, 从系统启动这一刻起开始计时, 如果你想计算出在一台计算机上不受重启的影响,两个事件发生的间隔时间的话,那么它将是最好的选择。
CLOCK_PROCESS_CPUTIME_ID : 本进程到当前代码系统CPU花费的时间
CLOCK_THREAD_CPUTIME_ID : 本线程到当前代码系统CPU花费的时间
POSIX-Data Structure