Linux RTC机制实现计时器类(2)

CTimer *CTimer::Instance()
{
    if (g_singleinstance == 0)
        g_singleinstance = new CTimer;
    return g_singleinstance;
}

void CTimer::SetInterval(long second)
{
    m_second = second * 2;
}

void CTimer::StartTimer()
{
    if (!(m_rtcfd > 0))
    {
        cout<<"TimerWarning: rtcfd < 0...Start failed..."<<endl;
        return;
    }
    if(ioctl(m_rtcfd, RTC_PIE_ON, 0) < 0)
    {
        cout<<"TimerWarning: ioctl(RTC_PIE_ON) failed..."<<endl;
        close(m_rtcfd);
        return;
    }
    m_counter = 0;
}

void CTimer::StopTimer()
{
    if (!(m_rtcfd > 0))
    {
        cout<<"TimerWarning: rtcfd < 0...Stop failed..."<<endl;
        return;
    }
    if(ioctl(m_rtcfd, RTC_PIE_OFF, 0) < 0)
    {
        cout<<"TimerWarning: ioctl(RTC_PIE_ON) failed..."<<endl;
        close(m_rtcfd);
        return;
    }
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwxsjz.html