samedi 9 juin 2018

What does SleepAndRun() and ThreadFunc() do in this code?

I want to implement a timer.h for my code. So i surf the net and found this piece of code working fine. but i would like to know about What SleepAndRun() and ThreadFunc() do in this code and why he define like that??

class Timer { std::thread Thread;//thread for Asynchronse code execu w/o blockingMainThread

bool Alive = false;//time is running or not

long CallNumber = -1L;//how many time a certain function should run.. -1 is jst for flexible.and long for overflow not happen as keyloagger runs for year


long repeat_count = -1L;//amount of time a certain function has ALREADY been called vs callnuber- determines how many time function GOING to call

std::chrono::milliseconds interval = std::chrono::milliseconds(0);

std::function<void(void)> funct = nullptr;//similar to pointer to function <void(void)>> which takes void arg and return void
//its is new type of pointer to functon in C++11

    void SleepAndRun ()
        {
        std::this_thread::sleep_for(interval);
        if (Alive)
            Function ()();
        } 

    void ThreadFunc ()
        {
        if (CallNumber == Infinite)
            while (Alive)
                SleepAndRun ();
        else
            while (repeat_count--)
                SleepAndRun ();
        }

    public: static const long Infinite = -1L;

Aucun commentaire:

Enregistrer un commentaire