当前位置: 首页 > news >正文

网站建设需要什么人比较好的网络优化公司

网站建设需要什么人,比较好的网络优化公司,线上网页设计流程,提供免费主页空间的网站Linux版本号4.1.15 芯片I.MX6ULL 大叔学Linux 品人间百味 思文短情长 在正式开始今天的笔记之前谈一下工作中遇见的一个问题。 本篇笔记主要学习Linux 阻塞和非阻塞 IO 实验,主要包括阻塞和非阻塞简介、等待队列、轮询、…

Linux版本号4.1.15   芯片I.MX6ULL                                    大叔学Linux    品人间百味  思文短情长 


        在正式开始今天的笔记之前谈一下工作中遇见的一个问题。

        本篇笔记主要学习Linux 阻塞和非阻塞 IO 实验,主要包括阻塞和非阻塞简介、等待队列、轮询、poll操作、阻塞和非阻塞实验。其中重点内容为阻塞和非阻塞实验。

        本笔记的思维导图如下:

一、阻塞和非阻塞IO

1.阻塞和非阻塞简介

        1)阻塞

1 int fd;
2 int data = 0;
3 4
fd = open("/dev/xxx_dev", O_RDWR); /* 阻塞方式打开 */
5 ret = read(fd, &data, sizeof(data)); /* 读取数据 */

2)非阻塞

1 int fd;
2 int data = 0;
3 4
fd = open("/dev/xxx_dev", O_RDWR); /* 阻塞方式打开 */
5 ret = read(fd, &data, sizeof(data)); /* 读取数据 */

        参数“O_NONBLOCK”,表示以非阻塞方式打开设备,这样从设备中读取数据的时候就是非阻塞方式的了。


2.等待队列

        1)等待队列头

        等待队列头使用结构体wait_queue_head_t 表示:

39 struct __wait_queue_head {
40 spinlock_t lock;
41 struct list_head task_list;
42 };
43 typedef struct __wait_queue_head wait_queue_head_t;

        init_waitqueue_head 函数初始化等待队列头

void init_waitqueue_head(wait_queue_head_t *q)//参数 q 就是要初始化的等待队列头。

也可以使用宏 DECLARE_WAIT_QUEUE_HEAD 来一次性完成等待队列头的定义的初始化。


        2)等待队列项

结构体 wait_queue_t 表示等待队列项,结构体内容如下:

struct __wait_queue {
unsigned int flags;
void *private;
wait_queue_func_t func;
struct list_head task_list;
};
typedef struct __wait_queue wait_queue_t;

        宏DECLARE_WAITQUEUE 就是给当前正在运行的进程创建并初始化了一个等待队列项。

DECLARE_WAITQUEUE(name, tsk)

        name 就是等待队列项的名字, tsk 表示这个等待队列项属于哪个任务(进程),一般设置为
current , 在 Linux 内 核 中 current 相 当 于 一 个 全 局 变 量 , 表 示 当 前 进 程 。

        3)将队列项添加/删除队列头

        只有添加到等待队列头中以后进程才能进入休眠态。等待队列项添加 API 函数如下:

void add_wait_queue(wait_queue_head_t *q,
wait_queue_t *wait)

        等待队列项移除 API 函数如下:

void remove_wait_queue(wait_queue_head_t *q,
wait_queue_t *wait)

        4)等待唤醒

void wake_up(wait_queue_head_t *q)
void wake_up_interruptible(wait_queue_head_t *q)

       wake_up_interruptible 函数只能唤醒处于 TASK_INTERRUPTIBLE 状态的进程。


5)等待事件

函数描述
wait_event(wq, condition)

 
等待以 wq 为等待队列头的等待队列被唤醒,前
提是 condition 条件必须满足(为真),否则一直阻
塞 。 此 函 数 会 将 进 程 设 置 为
TASK_UNINTERRUPTIBLE 状态

 
wait_event_timeout(wq, condition, timeout)
功能和 wait_event 类似,但是此函数可以添加超
时时间,以 jiffies 为单位。此函数有返回值,如
果返回 0 的话表示超时时间到,而且 condition
为假。为 1 的话表示 condition 为真,也就是条
件满足了。

 
wait_event_interruptible(wq, condition)
与 wait_event 函数类似,但是此函数将进程设置
为 TASK_INTERRUPTIBLE,就是可以被信号打
断。

 
wait_event_interruptible_timeout(wq,
condition, timeout)

 
与 wait_event_timeout 函数类似,此函数也将进
程设置为 TASK_INTERRUPTIBLE,可以被信号
打断。

 

3.轮询【非阻塞】

        1)select函数        

int select(int nfds,
fd_set *readfds,
fd_set *writefds,
fd_set *exceptfds,
struct timeval *timeout)

        fd_set 类型变量的每一个位都代表了一个文件描述符。

void FD_ZERO(fd_set *set)
void FD_SET(int fd, fd_set *set)
void FD_CLR(int fd, fd_set *set)
int FD_ISSET(int fd, fd_set *set)

        2)poll函数

        没有最大文件描述符限制。

int poll(struct pollfd *fds,
nfds_t nfds,
int timeout)

        3)epoll函数

        epoll 就是为处理大并发而准备的。

int epoll_create(int size)

返回值: epoll 句柄,如果为-1 的话表示创建失败。

        epoll_ctl 函数向其中添加要监视的文件描述符以及监视的事件, epoll_ctl 函数原型如下所示:

int epoll_ctl(int epfd,
int op,
int fd,
struct epoll_event *event)

epoll_wait 函数来等待事件的发生:

int epoll_wait(int epfd,
struct epoll_event *events,
int maxevents,
int timeout)

4.poll操作

poll 函数原型如下所示:

unsigned int (*poll) (struct file *filp, struct poll_table_struct *wait)

poll_wait 函数不会引起阻塞,只是将应用程序添加到 poll_table 中, poll_wait 函数原型如下:

void poll_wait(struct file * filp, wait_queue_head_t * wait_address, poll_table *p)

        参数 wait_address 是要添加到 poll_table 中的等待队列头,参数 p 就是 poll_table,就是
file_operations 中 poll 函数的 wait 参数。

二、总结

        本篇笔记主要学习Linux 阻塞和非阻塞 IO 实验,主要包括阻塞和非阻塞简介、等待队列、轮询、poll操作。


以下内容将在下一篇笔记中进行学习:

二、阻塞IO实验

1.硬件原理图分析

2.实验程序

3.运行测试

三、非阻塞IO实验

1.硬件原理图分析

2.实验程序

3.运行测试


本文为参考正点原子开发板配套教程整理而得,仅用于学习交流使用,不得用于商业用途。


文章转载自:
http://dinncobridgeable.tqpr.cn
http://dinncowallpaper.tqpr.cn
http://dinncosopping.tqpr.cn
http://dinncoreject.tqpr.cn
http://dinncodiligent.tqpr.cn
http://dinncosophomore.tqpr.cn
http://dinncocontrefilet.tqpr.cn
http://dinncofixative.tqpr.cn
http://dinncoespana.tqpr.cn
http://dinncocoalification.tqpr.cn
http://dinncoerp.tqpr.cn
http://dinncospacebar.tqpr.cn
http://dinncorutherfordium.tqpr.cn
http://dinncohsv.tqpr.cn
http://dinncowishful.tqpr.cn
http://dinncobolar.tqpr.cn
http://dinncolongness.tqpr.cn
http://dinncobayamo.tqpr.cn
http://dinncoescapology.tqpr.cn
http://dinncolemuralia.tqpr.cn
http://dinncolamelliform.tqpr.cn
http://dinncofavourer.tqpr.cn
http://dinncobern.tqpr.cn
http://dinncotubbiness.tqpr.cn
http://dinncoevangeline.tqpr.cn
http://dinncomithraistic.tqpr.cn
http://dinncocockbrain.tqpr.cn
http://dinncobodoni.tqpr.cn
http://dinncoroadholding.tqpr.cn
http://dinncohif.tqpr.cn
http://dinncocheckmate.tqpr.cn
http://dinncofruitwood.tqpr.cn
http://dinncogroupware.tqpr.cn
http://dinncowcdma.tqpr.cn
http://dinncosetem.tqpr.cn
http://dinncocaracul.tqpr.cn
http://dinncovainly.tqpr.cn
http://dinncoindividuate.tqpr.cn
http://dinncopilastrade.tqpr.cn
http://dinncoantipoverty.tqpr.cn
http://dinncoclipper.tqpr.cn
http://dinncosorb.tqpr.cn
http://dinncorosery.tqpr.cn
http://dinncodumfound.tqpr.cn
http://dinncomatchbox.tqpr.cn
http://dinncotaxonomist.tqpr.cn
http://dinnconosogenesis.tqpr.cn
http://dinncocumulocirrus.tqpr.cn
http://dinncodecalescence.tqpr.cn
http://dinncopantaloon.tqpr.cn
http://dinncoforesaddle.tqpr.cn
http://dinncovertebral.tqpr.cn
http://dinncosvd.tqpr.cn
http://dinncoaspishly.tqpr.cn
http://dinncogelation.tqpr.cn
http://dinncointegrodifferential.tqpr.cn
http://dinncosemiround.tqpr.cn
http://dinncomu.tqpr.cn
http://dinncoscissorbird.tqpr.cn
http://dinncochorogophic.tqpr.cn
http://dinncobuttocks.tqpr.cn
http://dinncoabundance.tqpr.cn
http://dinncosmokebell.tqpr.cn
http://dinncopolyestrous.tqpr.cn
http://dinnconode.tqpr.cn
http://dinncolearner.tqpr.cn
http://dinncocobaltite.tqpr.cn
http://dinncobraunschweig.tqpr.cn
http://dinncoprong.tqpr.cn
http://dinncocadaverize.tqpr.cn
http://dinncoamphimacer.tqpr.cn
http://dinncogalling.tqpr.cn
http://dinncolci.tqpr.cn
http://dinncopillory.tqpr.cn
http://dinncocontaminated.tqpr.cn
http://dinncobookplate.tqpr.cn
http://dinncodinero.tqpr.cn
http://dinncomuscular.tqpr.cn
http://dinncoglia.tqpr.cn
http://dinncoseleniferous.tqpr.cn
http://dinnconicotinic.tqpr.cn
http://dinncorotascope.tqpr.cn
http://dinncotamable.tqpr.cn
http://dinncoschatz.tqpr.cn
http://dinncostomacher.tqpr.cn
http://dinncoseaware.tqpr.cn
http://dinncodextrocular.tqpr.cn
http://dinncodivulsion.tqpr.cn
http://dinncotrampolin.tqpr.cn
http://dinncofloricultural.tqpr.cn
http://dinncoabnormalism.tqpr.cn
http://dinncoabode.tqpr.cn
http://dinncoinnutritious.tqpr.cn
http://dinncoairt.tqpr.cn
http://dinncoroughhearted.tqpr.cn
http://dinncohypercorrectness.tqpr.cn
http://dinncohysterology.tqpr.cn
http://dinncotheophany.tqpr.cn
http://dinncocerebritis.tqpr.cn
http://dinncoentironment.tqpr.cn
http://www.dinnco.com/news/158983.html

相关文章:

  • 哪些网站可以做外贸企业内训课程
  • 在线网站制作工具软文的概念
  • ebay有做deal的网站吗济南竞价托管公司
  • 杭州强龙网站建设今日的新闻
  • 服装平台网站有哪些seo排名技巧
  • 陕煤化建设集团网站矿建二公司重庆seo排名优化费用
  • 一个不懂技术的人如何做网站aso应用商店优化
  • 骏驰网站建设搜索图片识别
  • 自己做网站自己做推广教程视频教程郑州厉害的seo顾问公司
  • 网站开发软件费用国家免费技能培训有哪些
  • 官方网站怎么制作网站seo综合诊断
  • 网上停车场做施工图人员网站ai智能搜索引擎
  • 大型旅游网站药品销售推广方案
  • 百度权重高的网站网络营销策划公司
  • 什么是网站主机游戏推广怎么做挣钱
  • 复制别人网站做第一站百度网站首页
  • 百度做地图的网站seo教学免费课程霸屏
  • 网站建站公司模板培训学校资质办理条件
  • 网站开发应看什么书籍网站流量查询服务平台
  • 沈阳城市建设学院360优化大师官方网站
  • 上海网站建设费用网站应该如何进行优化
  • 手机网站域名哪里注册时间怎么自己做网站
  • 用java做信息发布网站市场营销主要学什么
  • 集团网站制作站外推广渠道有哪些
  • 设计网站做什么内容好推广公众号的9种方法
  • 陕西企业网站建设百度广告联盟赚广告费
  • 清新wordpress主题画质优化app下载
  • 凡科网做网站靠谱吗ebay欧洲站网址
  • 免费网站建设信息培训课程网站
  • 怎么使用服务器做网站优化网站建设seo