- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
semaphore的实现机制详解(The implementation mechanism of semaphore is explained in detail)
semaphore的实现机制详解(The implementation mechanism of semaphore is explained in detail)
Semaphore is one of the most important and common synchronization methods in kernel, and its main feature is synchronization under Sleep mechanism. When gets a semaphore but not when he gets immediately, the current execution process into the Sleep state of waiting, when semaphore can obtain the running start, unlike splin lock in acquiring the lock time is BusyWait.
First look at its definition:
Struct semaphore {
Atomic_t count; / / atomic variables, is the actual code in the follow-up, we can see that the amount of signal we have set in the initialization of the.
Int sleepers; / / there are several waiting.
Wait_queue_head_t wait; / / wait queue
};
Initialization function:
Static, inline, void, sema_init (struct, semaphore, *sem, int, Val)
{
Atomic_set (sem-count, Val); / / atomic operations, the signal values for atomic operation value.
Sem-sleepers = 0; / / set for 0.
Init_waitqueue_head (sem-wait); / / initialize the waiting queue.
}
Now that youre done with the initialization function, lets look at a special case PV operation:
Static, inline, void, init_MUTEX (struct, semaphore, *sem)
{
Sema_init (SEM, 1);
}
Static, inline, void, init_MUTEX_LOCKED (struct, semaphore, *sem)
{
Sema_init (SEM, 0);
}
From what we can see, in fact, what we call the PV operation is to call sema_init to place the atomic variables 0 or 1 respectively.
Lets look at the specific operation function below:
Static, inline, void, down (struct, semaphore * SEM)
{
Might_sleep ();
__asm__ __volatile__ (...
Atomic down operation\n\t #
LOCK_PREFIX decl%0\n\t --sem-count / * * /
JNS 2f\n.
\tlea,%0,%%eax\n\t.
Call __down_failed\n.
2
: +m (sem-count)
:
Memory, ax);
}
About might_sleep ():
#define might_sleep () \ \
Do {__might_sleep (__FILE__, __LINE__); might_resched ();} while (0)
As you can see, it simply calls might_resched ():
#define (might_resched) (cond_resched)
It calls cond_resched ():
Int __sched cond_res
您可能关注的文档
- 27.1.1图形相似.ppt
- 3.1.4 光在球面上反射和折射.doc
- 3.1 光干涉条件3.2 3.3.ppt
- 3.2生活中透镜(自制)《课堂练习题》.ppt
- 3.2.1 从自然界中获取铁与铜 1.ppt
- 3.5显微镜与望远镜练习1.doc
- 3.4凸透镜成像规律眼睛与眼镜20101120.doc
- 3C与4H-SiC中电子结构与电荷转移.doc
- 3《透镜和其应用》测试题1.doc
- 3.1.干涉条件.ppt
- sketch插件(sketch插件).doc
- Si化学性质.doc
- sketchup的36种实用插件介绍(36 practical plug-ins for SketchUp).doc
- skf轴承(Skf轴承).doc
- sl血液循环(SL blood circulation).doc
- smt工艺基础入门(Introduction to fundamentals of SMT technology).doc
- soa概览(SOA概览).doc
- solidworks快捷键and使用技巧(SolidWorks shortcut key and using skills).doc
- source insight3 中文显示修正及键盘困扰(Source insight3 Chinese display correction and keyboard trouble).doc
- Solidworks钣金功能在弯曲件展开中应用.doc
文档评论(0)