⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 00000036.htm

📁 一份很好的linux入门资料
💻 HTM
字号:
<HTML><HEAD>  <TITLE>BBS水木清华站∶精华区</TITLE></HEAD><BODY><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER>发信人:&nbsp;boom&nbsp;(www),&nbsp;信区:&nbsp;Linux&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>标&nbsp;&nbsp;题:&nbsp;another&nbsp;way&nbsp;for&nbsp;C++&nbsp;in&nbsp;kernel&nbsp;<BR>发信站:&nbsp;BBS&nbsp;水木清华站&nbsp;(Sat&nbsp;Nov&nbsp;18&nbsp;13:23:56&nbsp;2000)&nbsp;<BR>&nbsp;<BR>前面的文章里面介绍过可以在kernel中用c++,但是需要崇写new,delete等等&nbsp;<BR>最近由人在rtlinux的mailing&nbsp;list&nbsp;上又提出了一种方法&nbsp;<BR>&nbsp;<BR>(rtlinux)&nbsp;<BR>On&nbsp;Fri,&nbsp;17&nbsp;Nov&nbsp;2000,&nbsp;Alexander&nbsp;Lichius&nbsp;wrote:&nbsp;<BR>><I>&nbsp;i&nbsp;tried&nbsp;to&nbsp;use&nbsp;c++&nbsp;because&nbsp;i&nbsp;wanted&nbsp;to&nbsp;estimate&nbsp;the&nbsp;performance&nbsp;of&nbsp;</I><BR>><I>&nbsp;plain&nbsp;C&nbsp;code&nbsp;and&nbsp;some&nbsp;C++&nbsp;&quot;object&nbsp;oriented&quot;&nbsp;code.&nbsp;but&nbsp;my&nbsp;humble&nbsp;trials&nbsp;</I><BR>><I>&nbsp;were&nbsp;killed&nbsp;at&nbsp;compile&nbsp;time.&nbsp;i&nbsp;think&nbsp;the&nbsp;macros&nbsp;for&nbsp;using&nbsp;module&nbsp;</I><BR>><I>&nbsp;parameters&nbsp;are&nbsp;not&nbsp;defined&nbsp;in&nbsp;the&nbsp;g++&nbsp;standard&nbsp;include&nbsp;files&nbsp;and&nbsp;i&nbsp;</I><BR>><I>&nbsp;didn't&nbsp;have&nbsp;the&nbsp;time&nbsp;to&nbsp;track&nbsp;down&nbsp;the&nbsp;definition&nbsp;in&nbsp;the&nbsp;C&nbsp;includes.&nbsp;</I><BR>&nbsp;<BR>Hi&nbsp;Alexander&nbsp;and&nbsp;Jef,&nbsp;<BR>I&nbsp;think&nbsp;they&nbsp;are&nbsp;defined&nbsp;in&nbsp;linux/module.h&nbsp;<BR>&nbsp;<BR>I&nbsp;have&nbsp;tried&nbsp;to&nbsp;compile&nbsp;a&nbsp;module&nbsp;in&nbsp;C++,&nbsp;but&nbsp;some&nbsp;of&nbsp;the&nbsp;necessary&nbsp;<BR>kernel&nbsp;module&nbsp;#include&nbsp;files&nbsp;use&nbsp;C++&nbsp;reserved&nbsp;words&nbsp;as&nbsp;variable&nbsp;names.&nbsp;<BR>e.g.,&nbsp;there&nbsp;is&nbsp;a&nbsp;variable&nbsp;called&nbsp;&quot;new&quot;&nbsp;(it&nbsp;is&nbsp;C,&nbsp;not&nbsp;C++,&nbsp;so&nbsp;it&nbsp;is&nbsp;ok)&nbsp;<BR>&nbsp;<BR>therefore,&nbsp;I&nbsp;could&nbsp;not&nbsp;compile&nbsp;C++&nbsp;directly,&nbsp;but&nbsp;I&nbsp;did&nbsp;this&nbsp;way&nbsp;<BR>(skeleton&nbsp;code,&nbsp;missing&nbsp;many&nbsp;details):&nbsp;<BR>&nbsp;<BR>file&nbsp;module_main_file.c&nbsp;(C,&nbsp;not&nbsp;C++,&nbsp;gcc,&nbsp;not&nbsp;g++)&nbsp;<BR>#define&nbsp;MODULE&nbsp;<BR>#define&nbsp;__KERNEL__&nbsp;<BR>#define&nbsp;__RT__&nbsp;<BR>..&nbsp;<BR>#include&nbsp;&lt;rtl_sched.h&gt;&nbsp;&nbsp;<BR>#include&nbsp;&lt;linux/module.h&gt;&nbsp;<BR>#include&nbsp;&lt;linux/kernel.h&gt;&nbsp;<BR>#include&nbsp;&lt;linux/version.h&gt;&nbsp;<BR>#include&nbsp;&quot;wrapper.c&quot;&nbsp;<BR>..&nbsp;<BR>int&nbsp;init_module()&nbsp;{&nbsp;<BR>...my&nbsp;rt&nbsp;stuff&nbsp;initilization,&nbsp;etc...&nbsp;<BR>pthread_create&nbsp;(&amp;mytask,&nbsp;NULL,&nbsp;execute_module,&nbsp;(void&nbsp;*)&nbsp;1);&nbsp;<BR>pthread_make_periodic_np&nbsp;(mytask,&nbsp;now&nbsp;+&nbsp;0.5&nbsp;*&nbsp;NSECS_PER_SEC,&nbsp;0.1&nbsp;*&nbsp;<BR>NSECS_PER_SEC);&nbsp;<BR>&nbsp;<BR>wrapper_init();&nbsp;<BR>}&nbsp;<BR>&nbsp;<BR>void*&nbsp;execute_module(void&nbsp;*data){&nbsp;<BR>&nbsp;&nbsp;while(1){&nbsp;<BR>wrapper_do();&nbsp;<BR>pthread_wait_np();&nbsp;<BR>&nbsp;&nbsp;}&nbsp;<BR>}&nbsp;<BR>&nbsp;<BR>void&nbsp;cleanup_module()&nbsp;{&nbsp;<BR>&nbsp;&nbsp;wrapper_close();&nbsp;<BR>&nbsp;&nbsp;pthread_delete_np&nbsp;(mytask);&nbsp;<BR>}&nbsp;<BR>&nbsp;<BR>----------------end&nbsp;of&nbsp;file&nbsp;<BR>&nbsp;<BR>file&nbsp;wrapper.cc&nbsp;<BR>&nbsp;<BR>MYMAINOBJECT&nbsp;myobj;&nbsp;<BR>&nbsp;<BR>void&nbsp;wrapper_init()&nbsp;{&nbsp;myobj.init();&nbsp;}&nbsp;<BR>void&nbsp;wrapper_do()&nbsp;{&nbsp;myobj.do();&nbsp;}&nbsp;<BR>void&nbsp;wrapper_close()&nbsp;{&nbsp;myobj.close();&nbsp;}&nbsp;<BR>&nbsp;<BR>this&nbsp;file&nbsp;I&nbsp;can&nbsp;compile&nbsp;with&nbsp;g++,&nbsp;and&nbsp;link&nbsp;with&nbsp;my&nbsp;c++&nbsp;.o&nbsp;files.&nbsp;&nbsp;<BR>then&nbsp;I&nbsp;link&nbsp;this&nbsp;.o&nbsp;file&nbsp;with&nbsp;the&nbsp;main&nbsp;module&nbsp;.o&nbsp;file&nbsp;and...&nbsp;voilla!&nbsp;my&nbsp;<BR>c++&nbsp;code&nbsp;works!&nbsp;<BR>&nbsp;<BR>Interesting:&nbsp;I&nbsp;use&nbsp;rtlinux&nbsp;2.0,&nbsp;but&nbsp;with&nbsp;rtlinux&nbsp;0.6&nbsp;and&nbsp;linux&nbsp;<BR>2.0.33&nbsp;I&nbsp;do&nbsp;not&nbsp;need&nbsp;this&nbsp;stuff:&nbsp;the&nbsp;main&nbsp;module&nbsp;can&nbsp;call&nbsp;my&nbsp;object&nbsp;and&nbsp;be&nbsp;<BR>compiledwith&nbsp;g++,&nbsp;no&nbsp;problem.&nbsp;<BR>&nbsp;<BR>><I>&nbsp;so&nbsp;i&nbsp;didn't&nbsp;bother&nbsp;about&nbsp;C++&nbsp;but&nbsp;wrote&nbsp;my&nbsp;tasks&nbsp;in&nbsp;C.&nbsp;</I><BR>><I>&nbsp;did&nbsp;you&nbsp;or&nbsp;anybody&nbsp;else&nbsp;compiled&nbsp;some&nbsp;working&nbsp;C++&nbsp;kernel&nbsp;modules?&nbsp;</I><BR>&nbsp;<BR>I&nbsp;know&nbsp;C++&nbsp;is&nbsp;not&nbsp;supported&nbsp;in&nbsp;the&nbsp;kernel,&nbsp;and&nbsp;many&nbsp;people&nbsp;do&nbsp;not&nbsp;like&nbsp;<BR>to&nbsp;hear&nbsp;&quot;c++&nbsp;and&nbsp;kernel&quot;,&nbsp;but&nbsp;c++&nbsp;can&nbsp;be&nbsp;still&nbsp;worth...&nbsp;<BR>&nbsp;<BR>-----------------------------------------------------------&nbsp;<BR>Luiz&nbsp;Gustavo&nbsp;Bizarro&nbsp;Mirisola&nbsp;<BR>Mestrando&nbsp;em&nbsp;Ciencia&nbsp;da&nbsp;Computacao&nbsp;-&nbsp;IC-Unicamp/LRV-IA-CTI&nbsp;&nbsp;<BR>MSc&nbsp;Student&nbsp;in&nbsp;Computer&nbsp;Science&nbsp;&nbsp;<BR>State&nbsp;University&nbsp;of&nbsp;Campinas,&nbsp;Brazil&nbsp;<BR><A HREF="mailto:mirisola@dcc.unicamp.br">mirisola@dcc.unicamp.br</A>&nbsp;<BR>-----------------------------------------------------------&nbsp;<BR>&nbsp;<BR>--&nbsp;[rtl]&nbsp;---&nbsp;<BR>To&nbsp;unsubscribe:&nbsp;<BR>echo&nbsp;&quot;unsubscribe&nbsp;rtl&quot;&nbsp;|&nbsp;mail&nbsp;<A HREF="mailto:majordomo@rtlinux.org">majordomo@rtlinux.org</A>&nbsp;OR&nbsp;<BR>echo&nbsp;&quot;unsubscribe&nbsp;rtl&nbsp;&lt;Your_email&gt;&quot;&nbsp;|&nbsp;mail&nbsp;<A HREF="mailto:majordomo@rtlinux.org">majordomo@rtlinux.org</A>&nbsp;<BR>---&nbsp;<BR>For&nbsp;more&nbsp;information&nbsp;on&nbsp;Real-Time&nbsp;Linux&nbsp;see:&nbsp;<BR><A HREF="http://www.rtlinux.org/rtlinux/">http://www.rtlinux.org/rtlinux/</A>&nbsp;<BR>&nbsp;<BR>--&nbsp;<BR>&nbsp;<BR>※&nbsp;来源:·BBS&nbsp;水木清华站&nbsp;smth.org·[FROM:&nbsp;202.112.137.7]&nbsp;<BR><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -