void DTimer::sheduleAtFixedRate(const ITimerTask &task, unsigned int delay, unsigned int interval) { if (interval == 0) { //no need to adept period when interval == 0 shedule(task, delay, interval); } else { if (_task != NULL) { //THROWN("shedule already run"); return; } _task = const_cast<ITimerTask*>(&task); //_canceled = false; _task->setValid(true); ITimerTask *tsafe = _task;//use this poiter for thread safty wait(delay); //while (!_canceled) { while (tsafe->isValid()) { int64 stime = Date::getCurrentTime(); tsafe->run(); int64 timeCost = (Date::getCurrentTime() - stime)/TIME_SCALE; int64 fixedDelay = timeCost > interval ? 0 : interval - timeCost; wait(fixedDelay); } } }
void proc_init() { kprintf("Initializing process manager...\n"); procs_list = kmalloc(sizeof(list_t)); idle_proc = create_proc((uint32)idle); strcpy(idle_proc->name, "sysidle"); idle_proc->state = PS_IDLE; //current_proc = idle_proc; shedule(); }
uint32 switch_task(uint32 old_esp) { if (current_proc != 0) { current_proc->esp = old_esp; current_proc->context = (context_t *)old_esp; } shedule(); tss->esp0 = current_proc->kernel_stack; vmm_set_current_page_directory(current_proc->page_dir); return current_proc->esp; }
void DTimer::shedule(const ITimerTask &task, const Date &firstTime, unsigned int interval) { int64 iCurTime = Date::getCurrentTime(); int64 delay = firstTime.time() - iCurTime; if (delay < 0) { THROW("TIMER_INVALID_START_TIME"); } //delay is milliseconds shedule(task, (unsigned int)delay/TIME_SCALE, interval); }