pintos (0) --前言

要完成pintos不仅需要理解操作系统理论,同时也需要:

  1. 一个好的IDE,良好的阅读代码环境是极其重要的,不论vim+ctags也好,Emacs,Sublime,Atom,Eclipse等也罢,进入函数内部阅读其内容的功能是必要的
  2. 仔细阅读帮助文档,仔细阅读每个代码文件:从LOADER开始,到init,再到usercode,了解从系统启动开始的每一步都做了什么;有哪些系统支持的数据结构和算法
  3. C的基本功,不必多说

环境配置参考:Getting Started with PintOS


几个重要的点:

1.关闭/恢复软中断,保证操作原子性:
enum intr_level old_level = intr_disable ();
//do something
intr_set_level (old_level);

许多函数需要在中断关闭的情况下调用。

2.线程主动释放CPU,重新进行调度:
thread_yield ();
3.一个神奇的宏:
/* Converts pointer to list element LIST_ELEM into a pointer to
   the structure that LIST_ELEM is embedded inside.  Supply the
   name of the outer structure STRUCT and the member name MEMBER
   of the list element.  See the big comment at the top of the
   file for an example. */
#define list_entry(LIST_ELEM, STRUCT, MEMBER)           \
        ((STRUCT *) ((uint8_t *) &(LIST_ELEM)->next     \
                     - offsetof (STRUCT, MEMBER.next)))

怎么用呢?struct里面若含有struct list_elem elem; 成员,只要一个该成员的指针,通过该宏就能找到对应struct的指针,例如:

list_entry(list_front(&ready_list), struct thread, elem)->priority;

原理目前还没搞懂

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值