Пример #1
0
static void schedule(struct thread *t)
{
	struct thread *current = current_thread();

	/* If t is NULL need to find new runnable thread. */
	if (t == NULL) {
		if (thread_list_empty(&runnable_threads))
			die("Runnable thread list is empty!\n");
		t = pop_runnable();
	} else {
		/* current is still runnable. */
		push_runnable(current);
	}
	switch_to_thread(t->stack_current, &current->stack_current);
}
Пример #2
0
 void tasklet_service::yield(tasklet& tasklet_)
 {
     if(_stop)
     {
         throw stop_exception();
     }
     if (empty_runnables())
     {
         return;
     }
     push_runnable(tasklet_);
     assert(!empty_runnables());
     tasklet& next = pop_runnable();
     switch_tasklet(tasklet_, next);
 }
Пример #3
0
static void idle_thread_init(void)
{
	struct thread *t;

	t = get_free_thread();

	if (t == NULL)
		die("No threads available for idle thread!\n");

	/* Queue idle thread to run once all other threads have yielded. */
	prepare_thread(t, idle_thread, NULL, call_wrapper, NULL);
	push_runnable(t);
	/* Mark the currently executing thread to cooperate. */
	thread_cooperate();
}
Пример #4
0
 bool tasklet_service::check_waittings()
 {
     if (_head_waittings == NULL)
     {
         assert(_tail_waittings == NULL);
         return false;
     }
     bool found = false;
     for (tasklet *it = _head_waittings; it != NULL;)
     {
         tasklet *next = it->_next_waitting;
         if (!_channel_manager.empty(it->_channel))
         {
             unpark(*it);
             push_runnable(*it);
             //这里是不是需要notify或者notify_all一下其他等待的threadlet呢?
             found = true;
         }
         it = next;
     }
     return found;
 }