thread.h
https://github.com/wookayin/pintos/blob/master/src/threads/thread.h
| #ifndef THREADS_THREAD_H | |
| #define THREADS_THREAD_H | |
| #include <debug.h> | |
| #include <list.h> | |
| #include <stdint.h> | |
| #ifdef VM | |
| #include "vm/page.h" | |
| #endif | |
| /* States in a thread's life cycle. */ | |
| enum thread_status | |
| { | |
| THREAD_RUNNING, /* Running thread. */ | |
| THREAD_READY, /* Not running but ready to run. */ | |
| THREAD_BLOCKED, /* Waiting for an event to trigger. */ | |
| THREAD_DYING /* About to be destroyed. */ | |
| }; | |
| /* Thread identifier type. | |
| You can redefine this to whatever type you like. */ | |
| typedef int tid_t; | |
| #define TID_ERROR ((tid_t) -1) /* Error value for tid_t. */ | |
| /* Thread priorities. */ | |
| #define PRI_MIN 0 /* Lowest priority. */ | |
| #define PRI_DEFAULT 31 /* Default priority. */ | |
| #define PRI_MAX 63 /* Highest priority. */ | |
| /* A kernel thread or user process. | |
| Each thread structure is stored in its own 4 kB page. The | |
| thread structure itself sits at the very bottom of the page | |
| (at offset 0). The rest of the page is reserved for the | |
| thread's kernel stack, which grows downward from the top of | |
| the page (at offset 4 kB). Here's an illustration: | |
| 4 kB +---------------------------------+ | |
| | kernel stack | | |
| | | | | |
| | | | | |
| | V | | |
| | grows downward | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| +---------------------------------+ | |
| | magic | | |
| | : | | |
| | : | | |
| | name | | |
| | status | | |
| 0 kB +---------------------------------+ | |
| The upshot of this is twofold: | |
| 1. First, `struct thread' must not be allowed to grow too | |
| big. If it does, then there will not be enough room for | |
| the kernel stack. Our base `struct thread' is only a | |
| few bytes in size. It probably should stay well under 1 | |
| kB. | |
| 2. Second, kernel stacks must not be allowed to grow too | |
| large. If a stack overflows, it will corrupt the thread | |
| state. Thus, kernel functions should not allocate large | |
| structures or arrays as non-static local variables. Use | |
| dynamic allocation with malloc() or palloc_get_page() | |
| instead. | |
| The first symptom of either of these problems will probably be | |
| an assertion failure in thread_current(), which checks that | |
| the `magic' member of the running thread's `struct thread' is | |
| set to THREAD_MAGIC. Stack overflow will normally change this | |
| value, triggering the assertion. */ | |
| /* The `elem' member has a dual purpose. It can be an element in | |
| the run queue (thread.c), or it can be an element in a | |
| semaphore wait list (synch.c). It can be used these two ways | |
| only because they are mutually exclusive: only a thread in the | |
| ready state is on the run queue, whereas only a thread in the | |
| blocked state is on a semaphore wait list. */ | |
| struct thread | |
| { | |
| /* Owned by thread.c. */ | |
| tid_t tid; /* Thread identifier. */ | |
| enum thread_status status; /* Thread state. */ | |
| char name[16]; /* Name (for debugging purposes). */ | |
| uint8_t *stack; /* Saved stack pointer. */ | |
| int priority; /* Priority. */ | |
| int original_priority; /* Priority, before donation */ | |
| struct list_elem allelem; /* List element for all threads list. */ | |
| struct list_elem waitelem; /* List element, stored in the wait_list queue */ | |
| int64_t sleep_endtick; /* The tick after which the thread should awake (if the thread is in sleep) */ | |
| /* Shared between thread.c and synch.c. */ | |
| struct list_elem elem; /* List element, stored in the ready_list queue */ | |
| // needed for priority donations | |
| struct lock *waiting_lock; /* The lock object on which this thread is waiting (or NULL if not locked) */ | |
| struct list locks; /* List of locks the thread holds (for multiple donations) */ | |
| #ifdef USERPROG | |
| /* Owned by userprog/process.c. */ | |
| uint32_t *pagedir; /* Page directory. */ | |
| // Project 2: file descriptors and process table | |
| /* Owned by userprog/process.c and userprog/syscall.c */ | |
| struct process_control_block *pcb; /* Process Control Block */ | |
| struct list child_list; /* List of children processes of this thread, | |
| each elem is defined by pcb#elem */ | |
| struct list file_descriptors; /* List of file_descriptors the thread contains */ | |
| struct file *executing_file; /* The executable file of associated process. */ | |
| uint8_t *current_esp; /* The current value of the user program’s stack pointer. | |
| A page fault might occur in the kernel, so we might | |
| need to store esp on transition to kernel mode. (4.3.3) */ | |
| #endif | |
| #ifdef VM | |
| // Project 3: Supplemental page table. | |
| struct supplemental_page_table *supt; /* Supplemental Page Table. */ | |
| // Project 3: Memory Mapped Files. | |
| struct list mmap_list; /* List of struct mmap_desc. */ | |
| #endif | |
| // Project 4: CWD. | |
| struct dir *cwd; | |
| /* Owned by thread.c. */ | |
| unsigned magic; /* Detects stack overflow. */ | |
| }; | |
| /* If false (default), use round-robin scheduler. | |
| If true, use multi-level feedback queue scheduler. | |
| Controlled by kernel command-line option "-o mlfqs". */ | |
| extern bool thread_mlfqs; | |
| void thread_init (void); | |
| void thread_start (void); | |
| void thread_tick (int64_t tick); | |
| void thread_print_stats (void); | |
| typedef void thread_func (void *aux); | |
| tid_t thread_create (const char *name, int priority, thread_func *, void *); | |
| void thread_block (void); | |
| void thread_unblock (struct thread *); | |
| void thread_sleep_until (int64_t wake_tick); | |
| struct thread *thread_current (void); | |
| tid_t thread_tid (void); | |
| const char *thread_name (void); | |
| void thread_exit (void) NO_RETURN; | |
| void thread_yield (void); | |
| /* Performs some operation on thread t, given auxiliary data AUX. */ | |
| typedef void thread_action_func (struct thread *t, void *aux); | |
| void thread_foreach (thread_action_func *, void *); | |
| int thread_get_priority (void); | |
| void thread_set_priority (int); | |
| void thread_priority_donate(struct thread *, int priority); | |
| int thread_get_nice (void); | |
| void thread_set_nice (int); | |
| int thread_get_recent_cpu (void); | |
| int thread_get_load_avg (void); | |
| #endif /* threads/thread.h */ |
thread.h的更多相关文章
- checking for event2/thread.h... no libevent_pthreads required, failing
/********************************************************************************** * checking for e ...
- 初识chromium thread的实现
接触chromium已有一段时间,写点东西学习一下吧. 首先说一下用法,如何利用chromium封装好的thread类来开一个线程.在base里有一个封装该类的头文件thread.h,include它 ...
- 封装Thread的两种方法 via C++ in Linux
方法一: 代理线程函数(proxyThreadFunc)作为类的静态成员函数, 回调函数指针作为类的私有成员变量 方法二: 代理线程函数(proxyThreadFunc)作为全局函数, 回调函数指针 ...
- Android native thread相关
几个主要的source code路径: /system/core/include/utils/threads.h /system/core/include/utils/Thread.h /system ...
- Android Framework中的线程Thread及它的threadLoop方法
当初跟踪Camera的代码中的时候一直追到了HAL层,而在Framework中的代码看见了许很多多的Thread.它们普遍的特点就是有一个threadLoop方法.依照字面的意思应该是这个线程能够循环 ...
- Libevent源码学习笔记一:event2/event.h
一.libevent标准使用方法: 每个程序使用Libevent必须include <event2/event.h> 头文件,并 传给 -levent 链接器.如果只是想使用主要的eve ...
- c++11 thread (目前我使用的ZThread库)
目前为止(2014-11-30),GCC其实已经基本上完全支持C++11的所有功能了,事实上从GCC4.7之后,就支持了-std=c++11选项,在4.7版本之前,也开始支持-std=c++0x的选项 ...
- 使用C++11的function/bind组件封装Thread以及回调函数的使用
之前在http://www.cnblogs.com/inevermore/p/4008572.html中采用面向对象的方式,封装了Posix的线程,那里采用的是虚函数+继承的方式,用户通过重写Thre ...
- Linux组件封装(三)使用面向对象编程封装Thread
C++11提供了thread,但是过于复杂,我们还是倾向于在项目中编写自己的Thread. Posix Thread的使用这里不再赘述. 重点是这个函数: #include <pthread.h ...
随机推荐
- 维基百科 MediaWiki API 解析
使用开放的 API 做一个自己的小项目,是一个很好的学习方法.但好像开放的 API 选择并不多.这里给大家多一个选择,简单介绍一下维基百科使用的 MediaWiki API. 简介 先简单介绍几个容易 ...
- 性能优化实战-join与where条件执行顺序
昨天经历了一场非常痛苦的性能调优过程,但是收获也是刻骨铭心的,感觉对sql引擎的原理有了进一步认识. 问题起源于测试人员测一个多条件检索的性能时,发现按某个条件查询会特别慢.对应的sql语句简化为: ...
- 原生js简易日历效果实现
这里我们将用原生js实现简易的日历,原理和之前的原生js选项卡差不多,不过也有些区别: 首先html代码: <div class="container"> <di ...
- Linux中设置vim自动在运算符号两边加上空格
vim中设置自动在=+-之类的运算符号左右两边加上空格.原版的vim不带这个功能,写出的代码例如z=x+y,不美观,很多编译器(如VS)能够自动在符号两边加上空格,如z = x + y,看起来比较美观 ...
- Java中使用MD5加密的简单实现
import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorith ...
- node——underscore的使用
我在做新闻页面时,需要将之前存好点的data.json里的数据显示在首页上,而首页的每条新闻数据不能直接写定在上面,所以我们要将data里面的数据传递进去.我们需要使用underscore的templ ...
- easyUI datagarid单元格动态合并
第二列根据第一列合并,第三列根据第二列合并.层级关系. /* * tableID表格的id * colList要合并的字段例如:"overcount,totalcount" */ ...
- ASP.NET Menu控件点击区域太小解决方法
ASP.NET自带的Menu控件点击区域比较小,基本就是文本范围和图片范围,在区域外虽然选择的项有颜色变化,但是这个时候点击是没有用的,体验不是很好 检查前台生成的HTML,是用td嵌套a标签,a标签 ...
- HDU 1828 Picture (线段树:扫描线周长)
依然是扫描线,只不过是求所有矩形覆盖之后形成的图形的周长. 容易发现,扫描线中的某一条横边对答案的贡献. 其实就是 加上/去掉这条边之前的答案 和 加上/去掉这条边之后的答案 之差的绝对值 然后横着竖 ...
- java实现组合数_n!_杨辉三角_组合数递推公式_回文数_汉诺塔问题
一,使用计算机计算组合数 1,设计思想 (1)使用组合数公式利用n!来计算Cn^k=n!/k!(n-k)!用递推计算阶乘 (2)使用递推的方法用杨辉三角计算Cn+1^k=Cn^k-1+Cn^k 通过数 ...