Beispiel #1
0
bool MiniLoop::DoWork()
{
    for (;;) {
        ReloadWorkQueue();
        if (work_job_.empty()) {
            break;
        }
        do 
        {
            PendingJob pending_job = work_job_.front();
            work_job_.pop();
            if (pending_job.delay_run_ticks > 0) {
                AddToDelayedWorkQueue(pending_job);
                if (delayed_job_.top().job == pending_job.job) {
                    pump_->ScheduleDelayedWork(pending_job.delay_run_ticks);
                }
            }
            else{
                if (DeferOrRunPendingJob(pending_job))
                    return true;
            }
        } while (!work_job_.empty());
    }
    return false;
}
Beispiel #2
0
	bool MessageLoop::DoWork() {
		//TODO(tangjie): add nestable task process.
		for (; ;) {
			ReloadWorkQueue();
			if (work_queue_.empty()) {
				break;
			}
			do {
				PendingTask task = work_queue_.front();
				work_queue_.pop();
				if (!task.delayed_run_time_.IsNull()) {
					AddToDelayedQueue(task);
					// if task is the first one which was pushed into queue. need to schedule delay work.
					if (delayed_work_queue_.top().sequence_num_ == task.sequence_num_) {
						pump_->ScheduleDelayWork(task.delayed_run_time_);
					}
				}else {
					if (DeferOrRunPendingTask(task)) {
						return true;
					}
				}
			}while(!work_queue_.empty());
		}
		return false;
	}
Beispiel #3
0
	MessageLoop::~MessageLoop() {
		assert(this == current());
		// Clean up any unprocessed tasks, but take care: deleting a task could
		// result in the addition of more tasks (e.g., via DeleteSoon).  We set a
		// limit on the number of times we will allow a deleted task to generate more
		// tasks.  Normally, we should only pass through this loop once or twice.  If
		// we end up hitting the loop limit, then it is probably due to one task that
		// is being stubborn.  Inspect the queues to see who is left.
		bool did_work;
		for (int i = 0; i < 100; ++i) {
			DeletePendingTasks();
			ReloadWorkQueue();
			// If we end up with empty queues, then break out of the loop.
			did_work = DeletePendingTasks();
			if (!did_work)
				break;
		}
		FOR_EACH_OBSERVER(DestructionObserver, destruction_observers_, PreDestroyCurrentMessageLoop());
		internal::LocalStorage<MessageLoop>::GetInstance()->Set(nullptr);
	}