epoll 및 timerfd linux API로 타이머 이벤트 루프를 작성했습니다. timerfd_gettime
의 magpage는 내용의 다음 타이머가 현재 무장 경우에 따라서 time_t가 0인지 확인하십시오.
The it_value field returns the amount of time until the timer will
next expire. If both fields of this structure are zero, then the
timer is currently disarmed.
확인하거나 내가 쓴 무장 해제 다음 코드를
bool timer_is_running(struct timer *timer)
{
struct itimerspec timerspec;
if(timerfd_gettime(timer->_timer_fd, &timerspec) == -1) {
printf("[TIMER] Could not get timer '%s' running status\n", timer->name);
return false;
}
printf("[TIMER] Checking running state of timer '%s' it_value.tv_sec = %"PRIu64", it_value.tv_nsec = %"PRIu64"\n", timer->name, (uint64_t) timerspec.it_value.tv_sec, (uint64_t) timerspec.it_value.tv_nsec == 0);
return timerspec.it_value.tv_sec != 0 && timerspec.it_value.tv_nsec != 0;
}
이 작동하지 않는 및 모든 타이머가보고되었다 무장 해제.
[TIMER] Checking running state of timer 'test' it_value.tv_sec = 0, it_value.tv_nsec = 4302591840
추가 조사 후에 만 tv_sec
필드가 무장 해제 타이머를 0으로 설정 보인다 내가 출력에서 보았을 때 나는 현재 무장 해제 타이머 다음 보았다.
이 프로그램은 MIPS 아키텍처 (OpenWRT)에서 커널 3.18.23에서 실행됩니다.
커널 구현에서 버그로 표시하기 전에 time_t == 0
을 수행하여 time_t
이 0인지 확인하는 것이 올바른지 알고 싶습니다. 아무도 이것을 확인할 수 있습니까?
종류와 관련, Daan
'& |'이 아닌 반환 된 표현식에'||'를 사용하십시오. – Peter
세 번째 인수는'timerspec.it_value.tv_nsec == 0'입니까? 타이머가 값을 가질 때 이것은 '0'으로 평가 될 것입니다. 필자는 형식 지정과 일치하는 64 비트 값이 아니기 때문에 묻습니다. –