Ticket #7953: reduce_idle_cpu_usage.patch

File reduce_idle_cpu_usage.patch, 2.2 KB (added by Jim Stichnoth <stichnot@…>, 14 years ago)
  • libs/libmythui/mythmainwindow.cpp

     
    102102    MediaPlayCallback playFn;
    103103};
    104104
     105void ImpreciseTimer::run(void)
     106{
     107    while (!m_ShouldQuit)
     108    {
     109        usleep(m_Usec);
     110        if (m_Running)
     111            emit timeout();
     112    }
     113}
     114
    105115class MythMainWindowPrivate
    106116{
    107117  public:
     
    149159
    150160    QObject *sysEventHandler;
    151161
    152     QTimer *drawTimer;
     162    ImpreciseTimer *drawTimer;
    153163    QVector<MythScreenStack *> stackList;
    154164    MythScreenStack *mainStack;
    155165
     
    478488    d->gestureTimer = new QTimer(this);
    479489    connect(d->gestureTimer, SIGNAL(timeout()), this, SLOT(mouseTimeout()));
    480490
    481     d->drawTimer = new QTimer(this);
     491    d->drawTimer = new ImpreciseTimer(this);
    482492    connect(d->drawTimer, SIGNAL(timeout()), this, SLOT(animate()));
    483     d->drawTimer->start(1000 / 70);
     493    d->drawTimer->start();
     494    d->drawTimer->startTimer(70);
    484495
    485496    d->AllowInput = true;
    486497
     
    962973    d->paintwin->raise();
    963974    d->paintwin->show();
    964975
    965     d->drawTimer->start(1000 / 70);
     976    d->drawTimer->startTimer(70);
    966977}
    967978
    968979void MythMainWindow::Show(void)
  • libs/libmythui/mythmainwindow_internal.h

     
    22#define MYTHMAINWINDOW_INT
    33
    44#include <QWidget>
     5#include <QThread>
    56
    67class MythMainWindow;
    78class MythMainWindowPrivate;
     
    5253    MythMainWindowPrivate *d;
    5354};
    5455
     56class ImpreciseTimer : public QThread
     57{
     58    Q_OBJECT
     59
     60  public:
     61    ImpreciseTimer(QObject *parent) : QThread(parent), m_Running(false),
     62        m_ShouldQuit(false), m_Usec(100000) {}
     63    ~ImpreciseTimer() { m_ShouldQuit = true; }
     64    void stop(void) { m_Running = false; }
     65    void startTimer(double framerate) { m_Usec = 1000000 / framerate; m_Running = true; }
     66
     67  protected:
     68    void run(void);
     69
     70  signals:
     71    void timeout(void);
     72
     73  private:
     74    volatile bool m_Running;
     75    volatile bool m_ShouldQuit;
     76    volatile useconds_t m_Usec;
     77};
     78
    5579#endif