Lines Matching refs:tfd
620 struct timerfd *tfd; in linux_timerfd_create() local
643 tfd = malloc(sizeof(*tfd), M_EPOLL, M_WAITOK | M_ZERO); in linux_timerfd_create()
644 tfd->tfd_clockid = clockid; in linux_timerfd_create()
645 mtx_init(&tfd->tfd_lock, "timerfd", NULL, MTX_DEF); in linux_timerfd_create()
647 callout_init_mtx(&tfd->tfd_callout, &tfd->tfd_lock, 0); in linux_timerfd_create()
648 knlist_init_mtx(&tfd->tfd_sel.si_note, &tfd->tfd_lock); in linux_timerfd_create()
654 finit(fp, fflags, DTYPE_LINUXTFD, tfd, &timerfdops); in linux_timerfd_create()
664 struct timerfd *tfd; in timerfd_close() local
666 tfd = fp->f_data; in timerfd_close()
667 if (fp->f_type != DTYPE_LINUXTFD || tfd == NULL) in timerfd_close()
670 timespecclear(&tfd->tfd_time.it_value); in timerfd_close()
671 timespecclear(&tfd->tfd_time.it_interval); in timerfd_close()
673 callout_drain(&tfd->tfd_callout); in timerfd_close()
675 seldrain(&tfd->tfd_sel); in timerfd_close()
676 knlist_destroy(&tfd->tfd_sel.si_note); in timerfd_close()
679 mtx_destroy(&tfd->tfd_lock); in timerfd_close()
680 free(tfd, M_EPOLL); in timerfd_close()
689 struct timerfd *tfd; in timerfd_read() local
693 tfd = fp->f_data; in timerfd_read()
694 if (fp->f_type != DTYPE_LINUXTFD || tfd == NULL) in timerfd_read()
701 mtx_lock(&tfd->tfd_lock); in timerfd_read()
703 if (tfd->tfd_canceled) { in timerfd_read()
704 tfd->tfd_count = 0; in timerfd_read()
705 mtx_unlock(&tfd->tfd_lock); in timerfd_read()
708 if (tfd->tfd_count == 0) { in timerfd_read()
710 mtx_unlock(&tfd->tfd_lock); in timerfd_read()
713 error = mtx_sleep(&tfd->tfd_count, &tfd->tfd_lock, PCATCH, "ltfdrd", 0); in timerfd_read()
718 count = tfd->tfd_count; in timerfd_read()
719 tfd->tfd_count = 0; in timerfd_read()
720 mtx_unlock(&tfd->tfd_lock); in timerfd_read()
723 mtx_unlock(&tfd->tfd_lock); in timerfd_read()
732 struct timerfd *tfd; in timerfd_poll() local
735 tfd = fp->f_data; in timerfd_poll()
736 if (fp->f_type != DTYPE_LINUXTFD || tfd == NULL) in timerfd_poll()
739 mtx_lock(&tfd->tfd_lock); in timerfd_poll()
740 if ((events & (POLLIN|POLLRDNORM)) && tfd->tfd_count > 0) in timerfd_poll()
743 selrecord(td, &tfd->tfd_sel); in timerfd_poll()
744 mtx_unlock(&tfd->tfd_lock); in timerfd_poll()
752 struct timerfd *tfd; in timerfd_kqfilter() local
754 tfd = fp->f_data; in timerfd_kqfilter()
755 if (fp->f_type != DTYPE_LINUXTFD || tfd == NULL) in timerfd_kqfilter()
763 kn->kn_hook = tfd; in timerfd_kqfilter()
764 knlist_add(&tfd->tfd_sel.si_note, kn, 0); in timerfd_kqfilter()
772 struct timerfd *tfd = kn->kn_hook; in filt_timerfddetach() local
774 mtx_lock(&tfd->tfd_lock); in filt_timerfddetach()
775 knlist_remove(&tfd->tfd_sel.si_note, kn, 1); in filt_timerfddetach()
776 mtx_unlock(&tfd->tfd_lock); in filt_timerfddetach()
782 struct timerfd *tfd = kn->kn_hook; in filt_timerfdread() local
784 return (tfd->tfd_count > 0); in filt_timerfdread()
821 linux_timerfd_clocktime(struct timerfd *tfd, struct timespec *ts) in linux_timerfd_clocktime() argument
824 if (tfd->tfd_clockid == CLOCK_REALTIME) in linux_timerfd_clocktime()
831 linux_timerfd_curval(struct timerfd *tfd, struct itimerspec *ots) in linux_timerfd_curval() argument
835 linux_timerfd_clocktime(tfd, &cts); in linux_timerfd_curval()
836 *ots = tfd->tfd_time; in linux_timerfd_curval()
853 struct timerfd *tfd; in linux_timerfd_gettime() local
860 tfd = fp->f_data; in linux_timerfd_gettime()
861 if (fp->f_type != DTYPE_LINUXTFD || tfd == NULL) { in linux_timerfd_gettime()
866 mtx_lock(&tfd->tfd_lock); in linux_timerfd_gettime()
867 linux_timerfd_curval(tfd, &ots); in linux_timerfd_gettime()
868 mtx_unlock(&tfd->tfd_lock); in linux_timerfd_gettime()
885 struct timerfd *tfd; in linux_timerfd_settime() local
903 tfd = fp->f_data; in linux_timerfd_settime()
904 if (fp->f_type != DTYPE_LINUXTFD || tfd == NULL) { in linux_timerfd_settime()
909 mtx_lock(&tfd->tfd_lock); in linux_timerfd_settime()
913 linux_timerfd_curval(tfd, &ots); in linux_timerfd_settime()
915 tfd->tfd_time = nts; in linux_timerfd_settime()
916 tfd->tfd_count = 0; in linux_timerfd_settime()
918 linux_timerfd_clocktime(tfd, &cts); in linux_timerfd_settime()
921 timespecadd(&tfd->tfd_time.it_value, &cts, in linux_timerfd_settime()
922 &tfd->tfd_time.it_value); in linux_timerfd_settime()
927 callout_reset(&tfd->tfd_callout, tvtohz(&tv), in linux_timerfd_settime()
928 linux_timerfd_expire, tfd); in linux_timerfd_settime()
929 tfd->tfd_canceled = false; in linux_timerfd_settime()
931 tfd->tfd_canceled = true; in linux_timerfd_settime()
932 callout_stop(&tfd->tfd_callout); in linux_timerfd_settime()
934 mtx_unlock(&tfd->tfd_lock); in linux_timerfd_settime()
952 struct timerfd *tfd; in linux_timerfd_expire() local
954 tfd = (struct timerfd *)arg; in linux_timerfd_expire()
956 linux_timerfd_clocktime(tfd, &cts); in linux_timerfd_expire()
957 if (timespeccmp(&cts, &tfd->tfd_time.it_value, >=)) { in linux_timerfd_expire()
958 if (timespecisset(&tfd->tfd_time.it_interval)) in linux_timerfd_expire()
959 timespecadd(&tfd->tfd_time.it_value, in linux_timerfd_expire()
960 &tfd->tfd_time.it_interval, in linux_timerfd_expire()
961 &tfd->tfd_time.it_value); in linux_timerfd_expire()
964 timespecclear(&tfd->tfd_time.it_value); in linux_timerfd_expire()
965 if (timespecisset(&tfd->tfd_time.it_value)) { in linux_timerfd_expire()
966 timespecsub(&tfd->tfd_time.it_value, &cts, &ts); in linux_timerfd_expire()
968 callout_reset(&tfd->tfd_callout, tvtohz(&tv), in linux_timerfd_expire()
969 linux_timerfd_expire, tfd); in linux_timerfd_expire()
971 tfd->tfd_count++; in linux_timerfd_expire()
972 KNOTE_LOCKED(&tfd->tfd_sel.si_note, 0); in linux_timerfd_expire()
973 selwakeup(&tfd->tfd_sel); in linux_timerfd_expire()
974 wakeup(&tfd->tfd_count); in linux_timerfd_expire()
975 } else if (timespecisset(&tfd->tfd_time.it_value)) { in linux_timerfd_expire()
976 timespecsub(&tfd->tfd_time.it_value, &cts, &ts); in linux_timerfd_expire()
978 callout_reset(&tfd->tfd_callout, tvtohz(&tv), in linux_timerfd_expire()
979 linux_timerfd_expire, tfd); in linux_timerfd_expire()