FreeBSD/sys/kern/kern_event.c
/*
 * data contains amount of time to sleep
 */
data contains amount of time to sleep
data contains amount of time to sleep
static int
filt_timerattach(struct knote *kn)
{
	struct callout *calloutp;
	sbintime_t to;
	unsigned int ncallouts;
	if ((intptr_t)kn->kn_sdata < 0)
		return (EINVAL);
	if ((intptr_t)kn->kn_sdata == 0 && (kn->kn_flags & EV_ONESHOT) == 0)
		kn->kn_sdata = 1;
	if (kn->kn_sfflags & ~NOTE_TIMER_PRECMASK)
		return (EINVAL);
	to = timer2sbintime(kn->kn_sdata, kn->kn_sfflags);
	if (to < 0)
		return (EINVAL);
	ncallouts = atomic_load_explicit(&kq_ncallouts, memory_order_relaxed);
	do {
		if (ncallouts >= kq_calloutmax)
			return (ENOMEM);
	} while (!atomic_compare_exchange_weak_explicit(&kq_ncallouts,
	    &ncallouts, ncallouts + 1, memory_order_relaxed,
	    memory_order_relaxed));
	kn->kn_flags |= EV_CLEAR;		
	kn->kn_status &= ~KN_DETACHED;		
	kn->kn_ptr.p_nexttime = malloc(sizeof(sbintime_t), M_KQUEUE, M_WAITOK);
	calloutp = malloc(sizeof(*calloutp), M_KQUEUE, M_WAITOK);
	callout_init(calloutp, 1);
	kn->kn_hook = calloutp;
	*kn->kn_ptr.p_nexttime = to + sbinuptime();
	callout_reset_sbt_on(calloutp, *kn->kn_ptr.p_nexttime, 0,
	    filt_timerexpire, kn, PCPU_GET(cpuid), C_ABSOLUTE);
	return (0);
}
static int filt_timerattach ( struct knote * kn ) { struct callout * calloutp ; sbintime_t to ; unsigned int ncallouts ; if ( ( intptr_t ) kn -> kn_sdata < 0 ) return ( EINVAL ) ; if ( ( intptr_t ) kn -> kn_sdata == 0 && ( kn -> kn_flags & EV_ONESHOT ) == 0 ) kn -> kn_sdata = 1 ; if ( kn -> kn_sfflags & ~ NOTE_TIMER_PRECMASK ) return ( EINVAL ) ; to = timer2sbintime ( kn -> kn_sdata , kn -> kn_sfflags ) ; if ( to < 0 ) return ( EINVAL ) ; ncallouts = atomic_load_explicit ( & kq_ncallouts , memory_order_relaxed ) ; do { if ( ncallouts >= kq_calloutmax ) return ( ENOMEM ) ; } while ( ! atomic_compare_exchange_weak_explicit ( & kq_ncallouts , & ncallouts , ncallouts + 1 , memory_order_relaxed , memory_order_relaxed ) ) ; kn -> kn_flags |= EV_CLEAR ; kn -> kn_status &= ~ KN_DETACHED ; kn -> kn_ptr . p_nexttime = malloc ( sizeof ( sbintime_t ) , M_KQUEUE , M_WAITOK ) ; calloutp = malloc ( sizeof ( * calloutp ) , M_KQUEUE , M_WAITOK ) ; callout_init ( calloutp , 1 ) ; kn -> kn_hook = calloutp ; * kn -> kn_ptr . p_nexttime = to + sbinuptime ( ) ; callout_reset_sbt_on ( calloutp , * kn -> kn_ptr . p_nexttime , 0 , filt_timerexpire , kn , PCPU_GET ( cpuid ) , C_ABSOLUTE ) ; return ( 0 ) ; }
data contains amount of time to sleep
data contains amount of time to sleep
/* Only precision unit are supported in flags so far */ /* automatically set */ /* knlist_add clears it */