| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- #include "../lib/kernel/print.h"
- #include "debug.h"
- #include "init.h"
- #include "memory.h"
- #include "../thread/thread.h"
- #include "interrupt.h"
- #include "../device/console.h"
- #include "../device/ioqueue.h"
- #include "../device/keyboard.h"
- void thread_a_func(void *);
- void thread_b_func(void *);
- int main(void)
- {
- put_str("I am kernel\n");
- init_all();
- // asm volatile("sti"); // 使能中断
- // ASSERT(1 == 2);
- // void *addr = get_kernel_pages(4);
- // put_str("\n get_kernel_page start vaddr is ");
- // put_int((uintptr_t)addr);
- // put_str("\n");
- thread_start("consumer_a", 31, thread_a_func, " A_");
- thread_start("consumer_b", 31, thread_b_func, " B_");
- intr_enable(); // 打开中断,使中断起作用
- // 主线程会一直执行, 直到被中断或被其他线程强制结束
- while (1)
- ;
- // {
- // console_put_str("Main ");
- // }
- return 0;
- }
- void thread_a_func(void *arg)
- {
- // 用 void 来表示通用类型,这样就可以传递任意类型的参数
- while (1)
- {
- enum intr_status old_status = intr_disable();
- if (!ioq_empty(&keyboard_buf))
- {
- console_put_str(arg);
- char byte = ioq_getchar(&keyboard_buf);
- console_put_char(byte);
- }
- intr_set_status(old_status);
- }
- }
- void thread_b_func(void *arg)
- {
- while (1)
- {
- enum intr_status old_status = intr_disable();
- if (!ioq_empty(&keyboard_buf))
- {
- console_put_str(arg);
- char byte = ioq_getchar(&keyboard_buf);
- console_put_char(byte);
- }
- intr_set_status(old_status);
- }
- }
|