mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-08 18:26:48 +00:00
doc: 锁机制的文档
This commit is contained in:
parent
1b4f812fe4
commit
6352836902
@ -19,6 +19,7 @@
|
||||
|
||||
kernel/boot/index
|
||||
kernel/core_api/index
|
||||
kernel/locking/index
|
||||
kernel/process_management/index
|
||||
kernel/memory_management/index
|
||||
kernel/filesystem/index
|
||||
|
@ -27,6 +27,7 @@ SLAB内存池提供小内存对象的分配功能。
|
||||
|
||||
#### 描述
|
||||
  该函数用于释放通过kmalloc申请的内存。如果`address`为NULL,则函数被调用后,无事发生。
|
||||
|
||||
  请不要通过这个函数释放那些不是从`kmalloc()`申请的内存,否则将会导致系统崩溃。
|
||||
|
||||
##### 参数
|
||||
|
10
docs/kernel/locking/index.rst
Normal file
10
docs/kernel/locking/index.rst
Normal file
@ -0,0 +1,10 @@
|
||||
====================================
|
||||
锁
|
||||
====================================
|
||||
|
||||
这里是DragonOS的锁变量的说明文档。
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
locks
|
36
docs/kernel/locking/locks.md
Normal file
36
docs/kernel/locking/locks.md
Normal file
@ -0,0 +1,36 @@
|
||||
# 锁的类型及其规则
|
||||
|
||||
## 简介
|
||||
|
||||
  DragonOS内核实现了一些锁,大致可以分为两类:
|
||||
|
||||
- 休眠锁
|
||||
- 自旋锁
|
||||
|
||||
## 锁的类型
|
||||
|
||||
### 休眠锁
|
||||
|
||||
  休眠锁只能在可抢占的上下文之中被获取。
|
||||
|
||||
  在DragonOS之中,实现了以下的休眠锁:
|
||||
|
||||
- semaphore
|
||||
|
||||
### 自旋锁
|
||||
|
||||
- spinlock_t
|
||||
|
||||
  进程在获取自旋锁后,将改变pcb中的锁变量持有计数,从而隐式地禁止了抢占。为了获得更多灵活的操作,spinlock还提供了以下的方法:
|
||||
|
||||
| 后缀 | 说明 |
|
||||
| ------------------------ | -------------------------- |
|
||||
| _irq() | 在加锁时关闭中断/在放锁时开启中断 |
|
||||
| _irqsave()/_irqrestore() | 在加锁时保存中断状态,并关中断/在放锁时恢复中断状态 |
|
||||
|
||||
|
||||
### semaphore信号量
|
||||
|
||||
  semaphore信号量是基于计数实现的。
|
||||
|
||||
  当可用资源不足时,尝试对semaphore执行down操作的进程将会被休眠,直到资源可用。
|
Loading…
x
Reference in New Issue
Block a user