linux内核在线阅读,Linux内核数据结构.pdf

Linux内核数据结构

Chapter 6

Kernel Data Structures

What’s discussed

• Linked lists

• Queues

• Maps

• Binary trees

A singly linked list

A doubly linked list

Circular Linked Lists

The Linux Kernel’s Implementation

• All methods are defined in

The Linked List Structure

Node

• the list_add() method adds a new node to

an existing linked list

• These methods, however, are generic:

They accept only list_head structures

• Using the macro container_of(), we can

easily find the parent structure containing

any given member variable

Defining a Linked List

• initializing the linked list at runtime

• or at compile time

List Heads

• you will generally want a special pointer

that refers to your linked list, without being

a list node itself

• this special node is in fact a normal

list_head:

Manipulating Linked Lists

• Adding a Node to a Linked List

• Deleting a Node from a Linked List

Manipulating Linked Lists

• Moving and Splicing Linked List Nodes

Traversing Linked Lists

• The Basic Approach

• The Usable Approach

• Real example:

Queues

• FIFOs( First in, First Out)

• generic queue implementation is called

kfifo

• implemented in kernel/kfifo.c and declared

in .

kfifo

• Linux’s kfifo works like most other queue

abstractions

• providing two primary operations:

– enqueue (named in)

– dequeue (named out)

Creating a Queue

Enqueuing & Dequeuing Data

Obtaining the Size of a Queue

• total size in bytes

• current size used in bytes

• available size in bytes

Resetting and Destroying the

Queue

Queue Usage Example

Maps

• known as an associative array

• a collection of unique keys

• each key is

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值