¹ØÓÚLinux KernelÖеĺ궨ÒålikelyºÍunlikely
ת×Ôhttp://blog.163.com/ericxia_gnikam/blog/static/969208792008102545614453/
ÔÚLinux kernelµÄÔ´´úÂëÖУ¬¾³£Äܼûµ½if(likely(x))»òif(unlikely(x))Ö®ÀàµÄÓ÷¨£¬ÆäÈ·Çк¬ÒåÐèҪ˵Ã÷һϣ¬ÒÔ±ã¸üºÃµÄÀí½âkernelµÄÔ´´úÂë¡£
likelyÓëunlikelyÕâÁ½¸öºêÔÚlinux/compiler.hÖе͍ÒåÈçÏ£º
#define likely(x) __builtin_expect(!!(x),1)
#define unlikely(x) __builtin_expect(!!(x),0)
ºÜÃ÷ÏÔ£¬ÐèÒªÏÈŪÇå³þÕâ¸ö__builtin_expect()º¯ÊýµÄÒâÒå¡£
__builtin_expect()ÊÇgccµÄÒ»¸öÄÚ½¨º¯Êý£¬ÆäÔÐÍÈçÏ£º
long __builtin_expect (long exp, long c);
¼Çס¸Ãº¯ÊýÓÉGCC±¾ÉíÌṩ£¬ÓÃÓÚÓÅ»¯´úÂë¡£Ö»ÖвÎÊýexpΪÈÎÒ»±í´ïʽ£¬c±ØÐëΪ³£Á¿Öµ£¬ÆäÒâÒåÊÇÔÚexp==cʱ£¬¸Ãº¯Êý·µ»Ø·Ç0Öµ£¬Òâ¼´Ï£Íûexp==c¡£
»Øµ½likelyºÍunlikely£¬likelyʵ¼ÊÊÇÏ£Íû±í´ïʽx==1£¬¼´±í´ïʽx³ÉÁ¢£¬²¢ÇÒÔÚ´úÂëʵ¼ÊÖ´ÐÐÖУ¬±í´ïʽxÔÚ¾ø´ó¶àÊýÇé¿öÏÂÊdzÉÁ¢µÄ£¬Ïà·´£¬unlikelyÊÇÏ£Íû±í´ïʽÔÚ¾ø´ó¶àÊýÇé¿öϲ»³ÉÁ¢£¬
Èç¹ûÓÐÏÂÁдúÂ룺
if(unlikely(a > b) {
foo();
}
Õâ¶Î´úÂëµÄÒâ˼ÊÇ£¬ÔÚ¾ø´ó¶àÊýÇé¿öÏÂa¡¡>¡¡bÕâ¸ö±í´ïʽÊDz»³ÉÁ¢µÄ£¬²»³ÉÁ¢Ê±Ö´Ðк¯Êýfoo().
ÁíÍâÓÐÒ»µãҪעÒâµÄÊÇ£¬ÓÉÓÚlikely¶¨ÒåʱÓõij£Á¿ÊÇ1£¬unlikelyÓõij£Á¿ÊÇ0£¬ÕâÕýºÃ·ûºÏc/c++ÓïÑÔÖÐbool±äÁ¿µÄʵ¼ÊÖµ£¬¶ø_builtin_expect()º¯Êý¶ÔexpÓëc½øÐÐÑϸñÏàµÈµÄ±È½ÏµÄ£¬
Òò´ËʹÓÃlikelyºÍunlikelyʱ£¬Æä²ÎÊýÓ¦¸ÃֻʹÓÃÂß¼±í´ïʽ£¬ÒòΪÂß¼±í´ïʽµÄÖµÖ»ÓÐ0»ò1¡£³ý·ÇÕæÒªÅжÏij¸ö±äÁ¿µÄÖµÊÇ1»ò0ʱ£¬²Å»á½«ÆäËüÀàÐ͵IJÎÊý´«¸ølikely»òunlikely¡£ÕâÒ»µã¿ÉÄܺܶàÈ˻᲻СÐÄÓÃ´í¡£
ʹÓÃÕâÁ½¸öºê¶¨ÒåµÄºÃ´¦ÊÇÓÅ»¯Ìõ¼þÅжÏ
Ïà¹ØÎĵµ£º
ÀýÒ»£º·¢ËÍSignaling Packet£º
Signaling CommandÊÇ2¸öBluetoothʵÌåÖ®¼äµÄL2CAP²ãÃüÁî´«Êä¡£ËùÒÔµÃSignaling CommandʹÓÃCID 0x0001.
¶à¸öCommand¿ÉÒÔÔÚÒ»¸öC-frame£¨control frame£©Öз¢ËÍ¡£
Èç¹ûÒªÖ±½Ó·¢ËÍSignaling Command.ÐèÒª½¨Á¢SOCK_RAWÀàÐ͵ÄL2CAPÁ¬½ÓSocket¡£ÕâÑù²ÅÓлú»á×Ô¼ºÌî³äCommand Code£¬Identi ......
תÌùµØÖ·£ºhttp://www.linuxsir.org/main/?q=node/137
×ܽ᣺
zhy2111314
À´×Ô£º
LinuxSir.Org
ÕûÀí£º
±±ÄÏÄϱ±
ͻ񻣼
±¾ÎÄÊÇfind ÃüÁîµÄÏêϸ˵Ã÷£¬¿É¹óµÄÊÇÕë¶Ô²ÎÊý¾ÙÁ˺ܶàµÄʵÀý£¬´óÁ¿µÄÀýÖ¤£¬ÈóõѧÕ߸üΪÈÝÒ×Àí½â£»±¾ÎÄÊÇzhyflyÐÖÌùÔÚÂÛ̳ÖУ»ÎÒ¶Ô±¾ÎĽøÐÐÁËÔÙ´ÎÕûÀí£¬Îª·½±ã´ó¼ÒÔĶÁ£»
Ŀ¼
°æÈ¨ÉùÃ÷
ǰ ......
¼ò½é
ÕâÆªÎÄÕÂÖ÷Òª¼Ç¼ÎÒÔÚÊÔͼ½â¾öÈçºÎ¾¡¿ÉÄܾ«È·µØÔÚij¸öÌØ¶¨µÄʱ¼ä¼ä¸ôÖ´ÐÐijÏî¾ßÌåÈÎÎñʱµÄ˼·Àú³Ì£¬²¢ÔÚºóÆÚ¶ÔÏà¹ØµÄAPI½øÐеĹéÄɺÍ×ܽᣬÒÔ±¸²Î¿¼¡£
ÎÊÌâÒý³ö
ºÜ¶àʱºò£¬ÎÒÃÇ»áÓÐÀàËÆ“ÿ¸ô¶à³¤Ê±¼äÖ´ÐÐijÏîÈÎÎñ
”µÄÐèÇó£¬Õ§¿´Õâ¸öÎÊÌâ²¢²»Äѽâ¾ö£¬ÊµÔò²¢²»ÈÝÒ×£¬ÓкܶàÒþº¬Ìõ¼þÐèÒª¿¼ÂÇ£¬Ö ......