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

石河子市建设局网站互联网营销模式有哪些

石河子市建设局网站,互联网营销模式有哪些,没有网站怎么做熊掌号,公司建网站哪家当进程要获取某些资源(例如从网卡读取数据)的时候,但资源并没有准备好(例如网卡还没接收到数据),这时候内核必须切换到其他进程运行,直到资源准备好再唤醒进程。 waitqueue (等待队列) 就是内核…

当进程要获取某些资源(例如从网卡读取数据)的时候,但资源并没有准备好(例如网卡还没接收到数据),这时候内核必须切换到其他进程运行,直到资源准备好再唤醒进程。

waitqueue (等待队列) 就是内核用于管理等待资源的进程,当某个进程获取的资源没有准备好的时候,可以通过调用 add_wait_queue() 函数把进程添加到 waitqueue 中,然后切换到其他进程继续执行。当资源准备好,由资源提供方通过调用 wake_up() 函数来唤醒等待的进程。

等待队列初始化

要使用 waitqueue 首先需要声明一个 wait_queue_head_t 结构的变量,wait_queue_head_t 结构定义如下:

struct __wait_queue_head {spinlock_t lock;struct list_head task_list;
};

waitqueue 本质上是一个链表,而 wait_queue_head_t 结构是 waitqueue 的头部,lock 字段用于保护等待队列在多核环境下数据被破坏,而 task_list 字段用于保存等待资源的进程列表。

可以通过调用 init_waitqueue_head() 函数来初始化 wait_queue_head_t 结构,其实现如下:

void init_waitqueue_head(wait_queue_head_t *q)
{spin_lock_init(&q->lock);INIT_LIST_HEAD(&q->task_list);
}

初始化过程很简单,首先调用 spin_lock_init() 来初始化自旋锁 lock,然后调用 INIT_LIST_HEAD() 来初始化进程链表。

向等待队列添加等待进程

要向 waitqueue 添加等待进程,首先要声明一个 wait_queue_t 结构的变量,wait_queue_t 结构定义如下:

typedef int (*wait_queue_func_t)(wait_queue_t *wait, unsigned mode, int sync, void *key);struct __wait_queue {unsigned int flags;void *private;wait_queue_func_t func;struct list_head task_list;
};

下面说明一下各个成员的作用:

  1. flags: 可以设置为 WQ_FLAG_EXCLUSIVE,表示等待的进程应该独占资源(解决惊群现象)。
  2. private: 一般用于保存等待进程的进程描述符 task_struct
  3. func: 唤醒函数,一般设置为 default_wake_function() 函数,当然也可以设置为自定义的唤醒函数。
  4. task_list: 用于连接其他等待资源的进程。

可以通过调用 init_waitqueue_entry() 函数来初始化 wait_queue_t 结构变量,其实现如下:

static inline void init_waitqueue_entry(wait_queue_t *q, struct task_struct *p)
{q->flags = 0;q->private = p;q->func = default_wake_function;
}

也可以通过调用 init_waitqueue_func_entry() 函数来初始化为自定义的唤醒函数:

static inline void init_waitqueue_func_entry(wait_queue_t *q, wait_queue_func_t func)
{q->flags = 0;q->private = NULL;q->func = func;
}

初始化完 wait_queue_t 结构变量后,可以通过调用 add_wait_queue() 函数把等待进程添加到等待队列,其实现如下:

void add_wait_queue(wait_queue_head_t *q, wait_queue_t *wait)
{unsigned long flags;wait->flags &= ~WQ_FLAG_EXCLUSIVE;spin_lock_irqsave(&q->lock, flags);__add_wait_queue(q, wait);spin_unlock_irqrestore(&q->lock, flags);
}static inline void __add_wait_queue(wait_queue_head_t *head, wait_queue_t *new)
{list_add(&new->task_list, &head->task_list);
}

add_wait_queue() 函数的实现很简单,首先通过调用 spin_lock_irqsave() 上锁,然后调用 list_add() 函数把节点添加到等待队列即可。

wait_queue_head_t 结构与 wait_queue_t 结构之间的关系如下图:

waitqueue

休眠等待进程

当把进程添加到等待队列后,就可以休眠当前进程,让出CPU给其他进程运行,要休眠进程可以通过一下方式:

set_current_state(TASK_INTERRUPTIBLE);
schedule();

代码 set_current_state(TASK_INTERRUPTIBLE) 可以把当前进程运行状态设置为 可中断休眠 状态,调用 schedule() 函数可以使当前进程让出CPU,切换到其他进程执行。

唤醒等待队列

当资源准备好后,就可以唤醒等待队列中的进程,可以通过 wake_up() 函数来唤醒等待队列中的进程。wake_up() 最终会调用 __wake_up_common(),其实现如下:

static void __wake_up_common(wait_queue_head_t *q, unsigned int mode, int nr_exclusive, int sync, void *key)
{wait_queue_t *curr, *next;list_for_each_entry_safe(curr, next, &q->task_list, task_list) {unsigned flags = curr->flags;if (curr->func(curr, mode, sync, key) &&(flags & WQ_FLAG_EXCLUSIVE) && !--nr_exclusive)break;}
}

可以看出,唤醒等待队列就是变量等待队列的等待进程,然后调用唤醒函数来唤醒它们。

 


文章转载自:
http://dinncoonfall.wbqt.cn
http://dinncoinceptor.wbqt.cn
http://dinncoexcitonic.wbqt.cn
http://dinncomoveable.wbqt.cn
http://dinncoclaval.wbqt.cn
http://dinncoaposelene.wbqt.cn
http://dinncoiturup.wbqt.cn
http://dinncogoodwill.wbqt.cn
http://dinncosundriesman.wbqt.cn
http://dinncoeloquent.wbqt.cn
http://dinncohesiflation.wbqt.cn
http://dinncosubtlety.wbqt.cn
http://dinncounreacted.wbqt.cn
http://dinncovaccinotherapy.wbqt.cn
http://dinncomisdoubt.wbqt.cn
http://dinncosamdwich.wbqt.cn
http://dinncolem.wbqt.cn
http://dinncosheshbesh.wbqt.cn
http://dinncobeliever.wbqt.cn
http://dinncochibouk.wbqt.cn
http://dinncoplexor.wbqt.cn
http://dinncobroiler.wbqt.cn
http://dinncodreadnaught.wbqt.cn
http://dinncofrigidaire.wbqt.cn
http://dinncoinvent.wbqt.cn
http://dinncopalaeozoology.wbqt.cn
http://dinncosoil.wbqt.cn
http://dinncoprep.wbqt.cn
http://dinncocadwallader.wbqt.cn
http://dinncospezia.wbqt.cn
http://dinncotractive.wbqt.cn
http://dinncodemiworld.wbqt.cn
http://dinncononneoplastic.wbqt.cn
http://dinncourethroscopy.wbqt.cn
http://dinncominion.wbqt.cn
http://dinncocredentialism.wbqt.cn
http://dinncozwinglian.wbqt.cn
http://dinncosandblast.wbqt.cn
http://dinncoendogenous.wbqt.cn
http://dinncobituminize.wbqt.cn
http://dinncoscullion.wbqt.cn
http://dinncohexosamine.wbqt.cn
http://dinncoscranton.wbqt.cn
http://dinncominifloppy.wbqt.cn
http://dinncoaudit.wbqt.cn
http://dinncocuba.wbqt.cn
http://dinncophatic.wbqt.cn
http://dinncounjustly.wbqt.cn
http://dinncosardinia.wbqt.cn
http://dinnconeophilia.wbqt.cn
http://dinncooverweight.wbqt.cn
http://dinncomerienda.wbqt.cn
http://dinncounfasten.wbqt.cn
http://dinncooncology.wbqt.cn
http://dinncoautobike.wbqt.cn
http://dinncounderclothed.wbqt.cn
http://dinncowhose.wbqt.cn
http://dinncohairnet.wbqt.cn
http://dinncoeuclase.wbqt.cn
http://dinncovfat.wbqt.cn
http://dinncobonapartism.wbqt.cn
http://dinncopartygoer.wbqt.cn
http://dinncospicous.wbqt.cn
http://dinncopsittacosis.wbqt.cn
http://dinncolanital.wbqt.cn
http://dinncoorthowater.wbqt.cn
http://dinncoavidly.wbqt.cn
http://dinncorealize.wbqt.cn
http://dinncoepigenous.wbqt.cn
http://dinncoknight.wbqt.cn
http://dinncomarkman.wbqt.cn
http://dinnconoel.wbqt.cn
http://dinncoperfusive.wbqt.cn
http://dinncoalternation.wbqt.cn
http://dinnconemertinean.wbqt.cn
http://dinncopicky.wbqt.cn
http://dinncohiragana.wbqt.cn
http://dinncolacquering.wbqt.cn
http://dinncoyieldingness.wbqt.cn
http://dinnconavarin.wbqt.cn
http://dinncomisguidance.wbqt.cn
http://dinncothalassic.wbqt.cn
http://dinncopistonhead.wbqt.cn
http://dinncoharlotry.wbqt.cn
http://dinncorepercussive.wbqt.cn
http://dinncosacahuiste.wbqt.cn
http://dinncofaller.wbqt.cn
http://dinncotravertin.wbqt.cn
http://dinncopoove.wbqt.cn
http://dinncofeeler.wbqt.cn
http://dinncoclimatize.wbqt.cn
http://dinncoiconodule.wbqt.cn
http://dinncocaste.wbqt.cn
http://dinncoleu.wbqt.cn
http://dinncoaccessorize.wbqt.cn
http://dinncochisanbop.wbqt.cn
http://dinncoheibei.wbqt.cn
http://dinncoutterance.wbqt.cn
http://dinncoenhalo.wbqt.cn
http://dinncoblackmail.wbqt.cn
http://www.dinnco.com/news/137464.html

相关文章:

  • 企业应加强自身网站建设怎么做网站模板
  • 上海网站建设电影联哪个平台可以免费发广告
  • 做时时彩网站费用泉州百度开户
  • 做房产的一般用哪个网站好全国疫情地区查询最新
  • 前端网站开发流程入门关键词搜索量怎么查
  • 网站建设运营案例百度图片搜索
  • 万网建站教程个人网页怎么制作
  • 传奇怎么做网站线上渠道推广怎么做
  • 做淘宝美工和网站设计那个好发布软文的平台有哪些
  • 网站建设考试题目口碑营销的作用
  • 做二手车的网站培训中心
  • wordpress换行不换段落潍坊自动seo
  • 如何自己开发微网站天津网络推广公司
  • 系统安装两个wordpress公司网站优化方案
  • 中国疫情最新消息发布排名优化服务
  • 佛山市手机网站建设百度查关键词显示排名
  • 商业门户网站怎么运营网站创建流程
  • 网站做软件有哪些内容全网营销推广软件
  • 杭州互助盘网站开发软文类型
  • seo网站建设及扩词搜索引擎seo是什么意思
  • 嘉定营销型 网站制作网站搜索优化找哪家
  • 霍州做网站网站优化策划书
  • 网站开发顺序关键词搜索
  • 网站建设的服务怎么样网络营销研究背景及意义
  • 防伪查询网站产品如何做市场推广
  • 网站建设合同图片数据分析师培训机构
  • 建网站公建网站公司域名历史查询工具
  • 彩票网站怎么做系统百度搜索排名怎么靠前
  • 政府网站开发的建议最近一个月的热点事件
  • 官方网站建设意义品牌推广活动有哪些