????????????????Linux???POSIX?????????????????ж?posix???????????????kernelposix-timers.c/h?У??????????????2.6.29??????????????????POSIX?????????????man?????
????Linux????POSIX?????????????????????????????

 

int timer_create(clockid_t which_clock?? struct sigevent* timer_event_spec?? timer_t* created_timer_id);
int timer_gettime(timer_t timer_id?? struct itimerspec* setting);
int timer_settime(timer_t timer_id?? int flags?? struct itimerspec* new_setting?? struct itimerspec* old_setting);
int timer_delete(timer_t timer_id);

????????????????Щ????????????磺

 

clock_nanosleep
clock_getres
clock_settime
clock_gettime
timer_getoverrun

??????????????/??????????????????timer_create??
????int timer_create(clockid_t which_clock?? struct sigevent* timer_event_spec?? timer_t* created_timer_id);
????????which_clock????????????CLOCK_REALTIME??CLOCK_MONOTONIC????????????????clock??
????????timer_event_spec??????????????????????kernel?У?timer_event_spec??it_sigev_notify???????SIGEV_SIGNAL??SIGEV_NONE??SIGEV_THREAD_ID???????????????????????????????????SIGEV_THREAD??SIGEV_THREAD?????????POSIX????????????????????????www.linuxidc.com???????????includeasm-genericsiginfo.h??????????

 

/*
* sigevent definitions
*
* It seems likely that SIGEV_THREAD will have to be handled from
* userspace?? libpthread transmuting it to SIGEV_SIGNAL?? which the
* thread manager then catches and does the appropriate nonsense.
* However?? everything is written out here so as to not get lost.
*/
#define SIGEV_SIGNAL   0     /* notify via signal */
#define SIGEV_NONE      1     /* other notification: meaningless */
#define SIGEV_THREAD  2     /* deliver via thread creation */
#define SIGEV_THREAD_ID 4       /* deliver to thread */

????????SIGEV_THREAD_ID?????????POSIX??????ó??????????????á??????????
????????created_timer_id????????????????????????????
???????濴????????????????????

 

int timer_create(clockid_t which_clock?? struct sigevent* timer_event_spec?? timer_t* created_timer_id);
struct k_itimer * new_timer = alloc_posix_timer(); // ??????????????
??????       // ????idr??齫new_timer?????id?????????????????
// ?????COCK_DISPATCH?????????common_timer_create????
CLOCK_DISPATCH(which_clock?? timer_create?? (new_timer));
??????       // ??struct sigevent* timer_event_spec???浽new_timer????????У???????                // ????????????????
??????       // ??new_timer????struct task_struct::signal->posix_timers?С???????????                        // ??it_sigev_notify???SIGEV_THREAD_ID?????task_struct??????????                        // ????????????????task_struct??????????????
// posix_timers??????????task????????????????????????????????                        // ???????????????????posix?????
common_timer_create?????????k_itimer?е?hrtimer??hrtimer??Linux?????????
static int common_timer_create(struct k_itimer *new_timer)
{
hrtimer_init(&new_timer->it.real.timer?? new_timer->it_clock?? 0);
return 0;
}