Beispiel #1
0
void kmain(s64 magic, s64 info)
{
	//vga_clear(COLOR_BLACK);
    idt_init();
    isr_init();

    serial_init();
	set_debug_traps();
    BREAKPOINT();

	cpuid_print();
	multiboot(magic, info);
	kmem_map();
    page_init();
    kmalloc_init();
    //vesa_init();

    root_init();
    pci_init();
    vm_init();
    syscall_init();
    timer_init();
    kbd_init();
    //mouse_init();

    console_init();

 	create_kthread(NULL, idle_thread, THREAD_PRI_LOW, NULL, NULL);
 	create_kthread(NULL, init_thread, THREAD_PRI_NORMAL, NULL, NULL);

    thread_schedule();
}
Beispiel #2
0
void down(sem_t* sem)
{
    assert(thread_current != NULL);

    PUSIF();

	spin_lock(&sem->lock);

	if (sem->flag)// 有多余的资源,直接退出
	{
		sem->flag = 0;
		spin_unlock(&sem->lock);
	}
	else
	{
		DListAddTail(&sem->wait_list, &thread_current->run_node);
        //list_append_tail(&sem->wait_list, thread_current);
        spin_unlock(&sem->lock);

        thread_current->wait_sem = sem;
        thread_schedule();
	}

	POPIF();
}
Beispiel #3
0
int
main(int argc, char *argv[])
{
    thread_init();
    thread_create(mythread);
    thread_create(mythread);
    thread_schedule();
    return 0;
}
Beispiel #4
0
static void
mythread(void)
{
    int i;
    printf(1, "my thread running\n");
    for (i = 0; i < 100; i++) {
        printf(1, "my thread 0x%x\n", (int) current_thread);
        thread_yield();
    }
    printf(1, "my thread: exit\n");
    current_thread->state = FREE;
    thread_schedule();
}
Beispiel #5
0
/*
 * 内核主函数
 */
void kernel_main()
{
	char *str = "\n\nGreenLeafOS version 0.01.\n";
	print(str);

	kernel_stack_top = (u32*)&tss.esp0;
	kernel_reenter = 0;
	thread_init();

	main_thread_create();

	thread_schedule();
	restart();

	while(1);
}
Beispiel #6
0
void thread_exit()
{
    spin_lock(&thread_current->lock);

    process_t* proc = thread_current->process;
	if(proc)
	{
		__sync_sub_and_fetch(&proc->thread_cnt, 1);
		if(proc->thread_cnt == 0)
		{
			ProcessFree(proc);
		}
	}

    kmfree(thread_current->kstack_start);
    kmfree(thread_current);
    thread_current = NULL;

    thread_schedule();
//    spin_unlock(&thread_current->lock);
}
Beispiel #7
0
void
thread_yield(void)
{
    current_thread->state = RUNNABLE;
    thread_schedule();
}